|
1 | 1 | import {Observable} from 'rxjs'; |
2 | 2 |
|
3 | | -import person from './../data/person'; |
4 | 3 | import PeopleAdapter from './PeopleAdapter'; |
5 | 4 |
|
6 | 5 | export default class PeopleJSONAdapter extends PeopleAdapter { |
7 | 6 | /** |
8 | | - * Returns an observable that emits person data. |
9 | | - * Person data comes from JSON file `person.json` in the data folder. |
| 7 | + * @typedef PeopleJSON |
| 8 | + * @param {object} datasource An object that contains a set of people keyed by ID. |
| 9 | + * @example |
| 10 | + * { |
| 11 | + * "userid-1": { |
| 12 | + * "ID": "userid-1", |
| 13 | + * "emails": [ |
| 14 | + * "webexcmps@gmail.com" |
| 15 | + * ], |
| 16 | + * "displayName": "Webex Component User", |
| 17 | + * "firstName": "Webex", |
| 18 | + * "LastName": "Component User", |
| 19 | + * "nickName": "Webex", |
| 20 | + * "avatar": "https://4b4dc97add6b1dcc891a-54bf3b4e4579920861d23cc001530c2a.ssl.cf1.rackcdn.com/V1~b33cb17c-42e3-41ac-a045-497e4002646c~697607d5347442a990719dd5d80ce379~1600", |
| 21 | + * "orgID": "Y2lzY29zcGFyazovL3VzL09SR0FOSVpBVElPTi9jb25zdW1lcg", |
| 22 | + * "status": "unknown" |
| 23 | + * } |
| 24 | + * } |
| 25 | + */ |
| 26 | + |
| 27 | + /** |
| 28 | + * Returns an observable that emits person data of the given ID. |
10 | 29 | * |
11 | | - * @param {String} id - ID of person to get |
12 | | - * @returns {Observable<PersonObject>} |
| 30 | + * @param {string} ID ID of person to get |
| 31 | + * @returns {Observable.<Person>} |
13 | 32 | * @memberof PeopleJSONAdapter |
14 | 33 | */ |
15 | | - getPerson(id) { |
| 34 | + getPerson(ID) { |
16 | 35 | return Observable.create((observer) => { |
17 | | - if (person.id === id) observer.next(person); |
18 | | - else observer.error(new Error(`Could not find person with id "${id}"`)); |
| 36 | + if (this.datasource[ID]) { |
| 37 | + observer.next(this.datasource[ID]); |
| 38 | + } else { |
| 39 | + observer.error(new Error(`Could not find person with ID "${ID}"`)); |
| 40 | + } |
19 | 41 |
|
20 | 42 | observer.complete(); |
21 | 43 | }); |
|
0 commit comments