forked from webex/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeopleJSONAdapter.js
89 lines (83 loc) · 2.42 KB
/
PeopleJSONAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {PeopleAdapter} from '@webex/component-adapter-interfaces';
import {Observable} from 'rxjs';
// TODO: Figure out how to import JS Doc definitions and remove duplication.
/**
* A Webex user.
*
* @external Person
* @see {@link https://github.com/webex/component-adapter-interfaces/blob/master/src/PeopleAdapter.js#L6}
*/
/**
* @typedef PeopleJSON
* @param {object} datasource An object that contains people keyed by ID.
* @example
* {
* "user-1": {
* "ID": "user-1",
* "emails": [
* ],
* "displayName": "Barbara German",
* "firstName": "Barbara",
* "lastName": "German",
* "nickName": "",
* "avatar": "<URL to avatar>",
* "orgID": "",
* "status": null
* },
* "user-2": {
* "ID": "user-2",
* "emails": [
* ],
* "displayName": "Giacomo Drago",
* "firstName": "Giacomo",
* "lastName": "Drago",
* "nickName": "",
* "avatar": "<URL to avatar>",
* "orgID": "",
* "status": "active"
* }
* }
*/
/**
* `PersonJSONAdapter` is an implementation of the `PeopleAdapter` interface.
* This implementation utilizes a JSON object as its source of people data.
*
* @see {@link PeopleJSON}
* @implements {PeopleAdapter}
*/
export default class PeopleJSONAdapter extends PeopleAdapter {
/**
* Returns an observable that emits person data of the current user.
* Once the data is emitted, the observable completes.
* To listen for data updates, `getMe()` should be concatenated with `getPerson()`.
*
* @see {@link getPerson}
* @returns {Observable.<Person>} Observable that emits data of the "current" user
*/
getMe() {
const defaultUserID = 'user1';
return Observable.create((observer) => {
observer.next(this.datasource[defaultUserID]);
observer.complete();
});
}
/**
* Returns an observable that emits person data of the given ID.
* For this implementation, once the data is emitted, the observable completes.
*
* @param {string} ID ID of person to get
* @returns {Observable.<Person>} Observable that emits data of the given person ID
*/
getPerson(ID) {
return Observable.create((observer) => {
if (this.datasource[ID]) {
observer.next(this.datasource[ID]);
} else {
observer.error(new Error(`Could not find person with ID "${ID}"`));
}
observer.complete();
});
}
}