Skip to content

Commit

Permalink
use a service
Browse files Browse the repository at this point in the history
  • Loading branch information
obedm503 committed Mar 24, 2018
1 parent a573444 commit 64066f7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/users/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inlineView, PLATFORM } from 'aurelia-framework';
import { inlineView, PLATFORM, autoinject } from 'aurelia-framework';
import view from './users.html';

interface IUser {
Expand All @@ -7,7 +7,16 @@ interface IUser {
html_url: string;
}

class Service {
async getUsers() {
const res = await fetch('https://api.github.com/search/users?q=aurelia');
const json = await res.json();
return json.items as IUser[];
}
}

@inlineView(view)
@autoinject
export class Users {
heading: string = 'Aurelia Github Users';
users: Array<IUser> = [];
Expand All @@ -16,13 +25,9 @@ export class Users {
*/
image: HTMLImageElement;

constructor() {}
constructor(private readonly service: Service) {}

async activate(): Promise<void> {
const response = await fetch(
'https://api.github.com/search/users?q=aurelia',
);
const json = await response.json();
this.users = json.items;
this.users = await this.service.getUsers();
}
}

0 comments on commit 64066f7

Please sign in to comment.