-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbaseline.mjs
51 lines (40 loc) · 1.26 KB
/
baseline.mjs
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
import _ from 'underscore';
import Class from 'class-con-leche';
const Baseline = Class.extend( {
initialize( services ) {
this.services = services;
// hook up dependencies
for( const thisServiceIdent in this.services ) {
this.services[ thisServiceIdent ].baseline = this;
for( const thisOtherServiceIdent in this.services ) {
this.services[ thisServiceIdent ].setDependency( thisOtherServiceIdent, this.services[ thisOtherServiceIdent ] );
}
}
},
merge( data, options ) {
options = _.extend( {}, { empty : false }, options );
if( data ) {
for( const thisServiceIdent in data ) {
if( this.services[ thisServiceIdent ] && _.isFunction( this.services[ thisServiceIdent ].merge ) ) {
if( options.empty ) this.services[ thisServiceIdent ].empty();
this.services[ thisServiceIdent ].merge( data[ thisServiceIdent ] );
}
}
}
},
toJSON() {
const json = {};
for( const thisServiceIdent in this.services ) {
const thisService = this.services[ thisServiceIdent ];
if( _.isFunction( thisService.toJSON ) ) {
json[ thisServiceIdent ] = thisService.toJSON();
}
}
return json;
}
} );
// eslint-disable-next-line no-unused-vars
function _isServer() {
return ( typeof window === 'undefined' );
}
export default Baseline;