@base-framework/base 2.6.1 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/base.js +1 -0
- package/package.json +30 -26
- package/.jshintrc +0 -3
- package/base.js +0 -41
- package/base.min.js +0 -1
- package/core.js +0 -1
- package/data-tracker.js +0 -351
- package/es5/base.js +0 -2968
- package/es5/modules/ajax.js +0 -663
- package/es5/modules/animation.js +0 -188
- package/es5/modules/animations.js +0 -1080
- package/es5/modules/atom.js +0 -65
- package/es5/modules/component.js +0 -1310
- package/es5/modules/data-binder.js +0 -1131
- package/es5/modules/data.js +0 -1808
- package/es5/modules/date.js +0 -525
- package/es5/modules/form-validator.js +0 -324
- package/es5/modules/history.js +0 -126
- package/es5/modules/html-builder.js +0 -461
- package/es5/modules/layout.js +0 -1679
- package/es5/modules/mouse.js +0 -124
- package/es5/modules/nav-link.js +0 -123
- package/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es5/modules/olderversions/animations-update.js +0 -1048
- package/es5/modules/olderversions/base-animations.js +0 -636
- package/es5/modules/olderversions/base-component-class.js +0 -100
- package/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es5/modules/olderversions/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es5/modules/olderversions/data-tracker.js +0 -187
- package/es5/modules/olderversions/event-update.js +0 -666
- package/es5/modules/olderversions/nav-link.js +0 -119
- package/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es5/modules/prototypes/ajax.js +0 -657
- package/es5/modules/prototypes/atom.js +0 -65
- package/es5/modules/prototypes/component.js +0 -972
- package/es5/modules/prototypes/data-binder.js +0 -1089
- package/es5/modules/prototypes/data.js +0 -1290
- package/es5/modules/prototypes/html-builder.js +0 -414
- package/es5/modules/prototypes/layout.js +0 -879
- package/es5/modules/router.js +0 -1680
- package/es5/modules/state.js +0 -274
- package/es6/.jshintrc +0 -3
- package/es6/base.js +0 -41
- package/es6/core.js +0 -1
- package/es6/data-tracker.js +0 -351
- package/es6/events.js +0 -602
- package/es6/legacy/es5/base.js +0 -2968
- package/es6/legacy/es5/modules/ajax.js +0 -663
- package/es6/legacy/es5/modules/animation.js +0 -188
- package/es6/legacy/es5/modules/animations.js +0 -1080
- package/es6/legacy/es5/modules/atom.js +0 -65
- package/es6/legacy/es5/modules/component.js +0 -1310
- package/es6/legacy/es5/modules/data-binder.js +0 -1131
- package/es6/legacy/es5/modules/data.js +0 -1808
- package/es6/legacy/es5/modules/date.js +0 -525
- package/es6/legacy/es5/modules/form-validator.js +0 -324
- package/es6/legacy/es5/modules/history.js +0 -126
- package/es6/legacy/es5/modules/html-builder.js +0 -461
- package/es6/legacy/es5/modules/layout.js +0 -1679
- package/es6/legacy/es5/modules/mouse.js +0 -124
- package/es6/legacy/es5/modules/nav-link.js +0 -123
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
- package/es6/legacy/es5/modules/prototypes/component.js +0 -972
- package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
- package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
- package/es6/legacy/es5/modules/router.js +0 -1680
- package/es6/legacy/es5/modules/state.js +0 -274
- package/es6/main.js +0 -1331
- package/es6/modules/ajax/ajax.js +0 -514
- package/es6/modules/animation/animation.js +0 -236
- package/es6/modules/animations/animation-controller.js +0 -231
- package/es6/modules/animations/animation.js +0 -64
- package/es6/modules/animations/attr-movement.js +0 -66
- package/es6/modules/animations/css-movement.js +0 -170
- package/es6/modules/animations/movement.js +0 -131
- package/es6/modules/animations/value.js +0 -187
- package/es6/modules/atom/atom.js +0 -54
- package/es6/modules/component/component.js +0 -230
- package/es6/modules/component/event-helper.js +0 -119
- package/es6/modules/component/jot.js +0 -144
- package/es6/modules/component/state-helper.js +0 -262
- package/es6/modules/component/unit.js +0 -551
- package/es6/modules/data/attrs.js +0 -40
- package/es6/modules/data/basic-data.js +0 -500
- package/es6/modules/data/data-utils.js +0 -29
- package/es6/modules/data/data.js +0 -3
- package/es6/modules/data/deep-data.js +0 -541
- package/es6/modules/data/model-service.js +0 -528
- package/es6/modules/data/model.js +0 -133
- package/es6/modules/data/simple-data.js +0 -33
- package/es6/modules/data-binder/connection-tracker.js +0 -113
- package/es6/modules/data-binder/connection.js +0 -16
- package/es6/modules/data-binder/data-binder.js +0 -352
- package/es6/modules/data-binder/data-pub-sub.js +0 -141
- package/es6/modules/data-binder/data-source.js +0 -56
- package/es6/modules/data-binder/element-source.js +0 -219
- package/es6/modules/data-binder/one-way-connection.js +0 -46
- package/es6/modules/data-binder/one-way-source.js +0 -43
- package/es6/modules/data-binder/source.js +0 -36
- package/es6/modules/data-binder/two-way-connection.js +0 -75
- package/es6/modules/data-binder/two-way-source.js +0 -41
- package/es6/modules/date/date.js +0 -544
- package/es6/modules/history/history.js +0 -89
- package/es6/modules/html-builder/html-builder.js +0 -434
- package/es6/modules/import/import.js +0 -390
- package/es6/modules/layout/layout-builder.js +0 -1269
- package/es6/modules/layout/layout-parser.js +0 -134
- package/es6/modules/layout/watcher-helper.js +0 -282
- package/es6/modules/mouse/mouse.js +0 -114
- package/es6/modules/router/component-helper.js +0 -163
- package/es6/modules/router/history-controller.js +0 -216
- package/es6/modules/router/nav-link.js +0 -124
- package/es6/modules/router/route.js +0 -401
- package/es6/modules/router/router.js +0 -789
- package/es6/modules/router/utils.js +0 -31
- package/es6/modules/state/state-target.js +0 -91
- package/es6/modules/state/state.js +0 -171
- package/es6/package-lock.json +0 -13
- package/es6/package.json +0 -28
- package/es6/shared/objects.js +0 -99
- package/events.js +0 -602
- package/legacy/es5/base.js +0 -2968
- package/legacy/es5/modules/ajax.js +0 -663
- package/legacy/es5/modules/animation.js +0 -188
- package/legacy/es5/modules/animations.js +0 -1080
- package/legacy/es5/modules/atom.js +0 -65
- package/legacy/es5/modules/component.js +0 -1310
- package/legacy/es5/modules/data-binder.js +0 -1131
- package/legacy/es5/modules/data.js +0 -1808
- package/legacy/es5/modules/date.js +0 -525
- package/legacy/es5/modules/form-validator.js +0 -324
- package/legacy/es5/modules/history.js +0 -126
- package/legacy/es5/modules/html-builder.js +0 -461
- package/legacy/es5/modules/layout.js +0 -1679
- package/legacy/es5/modules/mouse.js +0 -124
- package/legacy/es5/modules/nav-link.js +0 -123
- package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/legacy/es5/modules/prototypes/atom.js +0 -65
- package/legacy/es5/modules/prototypes/component.js +0 -972
- package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/legacy/es5/modules/prototypes/data.js +0 -1290
- package/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/legacy/es5/modules/prototypes/layout.js +0 -879
- package/legacy/es5/modules/router.js +0 -1680
- package/legacy/es5/modules/state.js +0 -274
- package/main.js +0 -1331
- package/modules/ajax/ajax.js +0 -514
- package/modules/animation/animation.js +0 -236
- package/modules/animations/animation-controller.js +0 -231
- package/modules/animations/animation.js +0 -64
- package/modules/animations/attr-movement.js +0 -66
- package/modules/animations/css-movement.js +0 -170
- package/modules/animations/movement.js +0 -131
- package/modules/animations/value.js +0 -187
- package/modules/atom/atom.js +0 -54
- package/modules/component/component.js +0 -230
- package/modules/component/event-helper.js +0 -119
- package/modules/component/jot.js +0 -144
- package/modules/component/state-helper.js +0 -262
- package/modules/component/unit.js +0 -551
- package/modules/data/attrs.js +0 -40
- package/modules/data/basic-data.js +0 -500
- package/modules/data/data-utils.js +0 -29
- package/modules/data/data.js +0 -3
- package/modules/data/deep-data.js +0 -541
- package/modules/data/model-service.js +0 -528
- package/modules/data/model.js +0 -133
- package/modules/data/simple-data.js +0 -33
- package/modules/data-binder/connection-tracker.js +0 -113
- package/modules/data-binder/connection.js +0 -16
- package/modules/data-binder/data-binder.js +0 -352
- package/modules/data-binder/data-pub-sub.js +0 -141
- package/modules/data-binder/data-source.js +0 -56
- package/modules/data-binder/element-source.js +0 -219
- package/modules/data-binder/one-way-connection.js +0 -46
- package/modules/data-binder/one-way-source.js +0 -43
- package/modules/data-binder/source.js +0 -36
- package/modules/data-binder/two-way-connection.js +0 -75
- package/modules/data-binder/two-way-source.js +0 -41
- package/modules/date/date.js +0 -544
- package/modules/history/history.js +0 -89
- package/modules/html-builder/html-builder.js +0 -434
- package/modules/import/import.js +0 -390
- package/modules/layout/layout-builder.js +0 -1269
- package/modules/layout/layout-parser.js +0 -134
- package/modules/layout/watcher-helper.js +0 -282
- package/modules/mouse/mouse.js +0 -114
- package/modules/router/component-helper.js +0 -163
- package/modules/router/history-controller.js +0 -216
- package/modules/router/nav-link.js +0 -124
- package/modules/router/route.js +0 -401
- package/modules/router/router.js +0 -789
- package/modules/router/utils.js +0 -31
- package/modules/state/state-target.js +0 -91
- package/modules/state/state.js +0 -171
- package/shared/objects.js +0 -99
- package/update +0 -16
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
import {DataPubSub} from '../data-binder/data-pub-sub.js';
|
|
2
|
-
import {setupAttrSettings} from './attrs.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* BasicData
|
|
6
|
-
*
|
|
7
|
-
* This will create a bindable base class. This will
|
|
8
|
-
* allow shallow one level deep data to be created
|
|
9
|
-
* and watched.
|
|
10
|
-
*
|
|
11
|
-
* @class
|
|
12
|
-
*/
|
|
13
|
-
export class BasicData
|
|
14
|
-
{
|
|
15
|
-
/**
|
|
16
|
-
* @constructor
|
|
17
|
-
* @param {object} [settings]
|
|
18
|
-
*/
|
|
19
|
-
constructor(settings)
|
|
20
|
-
{
|
|
21
|
-
this.dirty = false;
|
|
22
|
-
this.links = {};
|
|
23
|
-
|
|
24
|
-
this._init();
|
|
25
|
-
this.setup();
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @member {string} dataTypeId
|
|
29
|
-
*/
|
|
30
|
-
this.dataTypeId = 'bd';
|
|
31
|
-
|
|
32
|
-
/* this will setup the event sub for
|
|
33
|
-
one way binding */
|
|
34
|
-
this.eventSub = new DataPubSub();
|
|
35
|
-
|
|
36
|
-
/* this will set the construct attributes */
|
|
37
|
-
let attributes = setupAttrSettings(settings);
|
|
38
|
-
this.set(attributes);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setup()
|
|
42
|
-
{
|
|
43
|
-
this.stage = {};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* This will setup the number and unique id of the data object.
|
|
48
|
-
* @protected
|
|
49
|
-
*/
|
|
50
|
-
_init()
|
|
51
|
-
{
|
|
52
|
-
const constructor = this.constructor;
|
|
53
|
-
this._dataNumber = (typeof constructor._dataNumber === 'undefined')? constructor._dataNumber = 0 : (++constructor._dataNumber);
|
|
54
|
-
|
|
55
|
-
this._id = 'dt-' + this._dataNumber;
|
|
56
|
-
this._dataId = this._id + ':';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* This will get the data id.
|
|
61
|
-
* @return {string}
|
|
62
|
-
*/
|
|
63
|
-
getDataId()
|
|
64
|
-
{
|
|
65
|
-
return this._id;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* This is a placeholder.
|
|
70
|
-
*/
|
|
71
|
-
remove()
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* This will setup a one way bind.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} attrName
|
|
80
|
-
* @param {function} callBack
|
|
81
|
-
* @return {string} The subscription token.
|
|
82
|
-
*/
|
|
83
|
-
on(attrName, callBack)
|
|
84
|
-
{
|
|
85
|
-
let message = attrName + ':change';
|
|
86
|
-
let token = this.eventSub.on(message, callBack);
|
|
87
|
-
return token;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* This will unbind from a one way bind.
|
|
92
|
-
*
|
|
93
|
-
* @param {string} attrName
|
|
94
|
-
* @param {string} token
|
|
95
|
-
*/
|
|
96
|
-
off(attrName, token)
|
|
97
|
-
{
|
|
98
|
-
let message = attrName + ':change';
|
|
99
|
-
this.eventSub.off(message, token);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* This will set the attribute value.
|
|
104
|
-
*
|
|
105
|
-
* @protected
|
|
106
|
-
* @param {string} attr
|
|
107
|
-
* @param {*} val
|
|
108
|
-
* @param {object} committer
|
|
109
|
-
*/
|
|
110
|
-
_setAttr(attr, val, committer)
|
|
111
|
-
{
|
|
112
|
-
let prevValue = this.stage[attr];
|
|
113
|
-
if(val === prevValue)
|
|
114
|
-
{
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this.stage[attr] = val;
|
|
119
|
-
|
|
120
|
-
committer = committer || this;
|
|
121
|
-
|
|
122
|
-
/* this will publish the data to the data binder
|
|
123
|
-
to update any ui elements that are subscribed */
|
|
124
|
-
this._publish(attr, val, committer, prevValue);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* This will set the data value of an attribute or attributes.
|
|
129
|
-
*
|
|
130
|
-
* @param {string} key
|
|
131
|
-
* @param {*} value
|
|
132
|
-
*
|
|
133
|
-
* or
|
|
134
|
-
*
|
|
135
|
-
* @param {object} data
|
|
136
|
-
* @return {object} this
|
|
137
|
-
*/
|
|
138
|
-
set(...args)
|
|
139
|
-
{
|
|
140
|
-
if(typeof args[0] === 'object')
|
|
141
|
-
{
|
|
142
|
-
let [items, committer, stopMerge] = args;
|
|
143
|
-
|
|
144
|
-
for(var attr in items)
|
|
145
|
-
{
|
|
146
|
-
if(items.hasOwnProperty(attr))
|
|
147
|
-
{
|
|
148
|
-
var item = items[attr];
|
|
149
|
-
if(typeof item === 'function')
|
|
150
|
-
{
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
this._setAttr(attr, item, committer, stopMerge);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else
|
|
158
|
-
{
|
|
159
|
-
this._setAttr(...args);
|
|
160
|
-
}
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* This will get the model data.
|
|
166
|
-
*/
|
|
167
|
-
getModelData()
|
|
168
|
-
{
|
|
169
|
-
return this.stage;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* This will delete an attribute.
|
|
174
|
-
*
|
|
175
|
-
* @param {object} obj
|
|
176
|
-
* @param {string} attr
|
|
177
|
-
*/
|
|
178
|
-
_deleteAttr(obj, attr)
|
|
179
|
-
{
|
|
180
|
-
delete obj[attr];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* This will toggle a bool attribute.
|
|
185
|
-
*
|
|
186
|
-
* @param {string} attr
|
|
187
|
-
* @return {object} this
|
|
188
|
-
*/
|
|
189
|
-
toggle(attr)
|
|
190
|
-
{
|
|
191
|
-
if(typeof attr === 'undefined')
|
|
192
|
-
{
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
this.set(attr, !this.get(attr));
|
|
197
|
-
return this;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* This will increment an attribute.
|
|
202
|
-
*
|
|
203
|
-
* @param {string} attr
|
|
204
|
-
* @return {object} this
|
|
205
|
-
*/
|
|
206
|
-
increment(attr)
|
|
207
|
-
{
|
|
208
|
-
if(typeof attr === 'undefined')
|
|
209
|
-
{
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
let val = this.get(attr);
|
|
214
|
-
this.set(attr, ++val);
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* This will decrement an attribute.
|
|
220
|
-
*
|
|
221
|
-
* @param {string} attr
|
|
222
|
-
* @return {object} this
|
|
223
|
-
*/
|
|
224
|
-
decrement(attr)
|
|
225
|
-
{
|
|
226
|
-
if(typeof attr === 'undefined')
|
|
227
|
-
{
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
let val = this.get(attr);
|
|
232
|
-
this.set(attr, --val);
|
|
233
|
-
return this;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* This will set the key value if it is null.
|
|
238
|
-
*
|
|
239
|
-
* @param {string} key
|
|
240
|
-
* @param {mixed} value
|
|
241
|
-
* @return {object} this
|
|
242
|
-
*/
|
|
243
|
-
ifNull(key, value)
|
|
244
|
-
{
|
|
245
|
-
if(this.get(key) === null)
|
|
246
|
-
{
|
|
247
|
-
this.set(key, value);
|
|
248
|
-
}
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* This will set the data local storage key.
|
|
254
|
-
*
|
|
255
|
-
* @param {string} key
|
|
256
|
-
*/
|
|
257
|
-
setKey(key)
|
|
258
|
-
{
|
|
259
|
-
this.key = key;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* This will restore the data from local storage.
|
|
264
|
-
*
|
|
265
|
-
* @param {mixed} defaultValue
|
|
266
|
-
* @returns {bool|void}
|
|
267
|
-
*/
|
|
268
|
-
resume(defaultValue)
|
|
269
|
-
{
|
|
270
|
-
let key = this.key;
|
|
271
|
-
if(!key)
|
|
272
|
-
{
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let data;
|
|
277
|
-
let value = localStorage.getItem(key);
|
|
278
|
-
if(value === null)
|
|
279
|
-
{
|
|
280
|
-
if(defaultValue)
|
|
281
|
-
{
|
|
282
|
-
data = defaultValue;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
else
|
|
286
|
-
{
|
|
287
|
-
data = JSON.parse(value);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
this.set(data);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* This will store the data to the local stoage under
|
|
295
|
-
* the storage key.
|
|
296
|
-
*
|
|
297
|
-
* @returns {bool|void}
|
|
298
|
-
*/
|
|
299
|
-
store()
|
|
300
|
-
{
|
|
301
|
-
let key = this.key;
|
|
302
|
-
if(!key)
|
|
303
|
-
{
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
let data = this.get();
|
|
308
|
-
if(!data)
|
|
309
|
-
{
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
let value = JSON.stringify(data);
|
|
314
|
-
localStorage.setItem(key, value);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* This will delete a property value or the model data.
|
|
319
|
-
*
|
|
320
|
-
* @param {string} [attrName]
|
|
321
|
-
* @return {*}
|
|
322
|
-
*/
|
|
323
|
-
delete(attrName)
|
|
324
|
-
{
|
|
325
|
-
if(typeof attrName !== 'undefined')
|
|
326
|
-
{
|
|
327
|
-
this._deleteAttr(this.stage, attrName);
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// this will clear the stage and attributes
|
|
332
|
-
this.setup();
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* This will get the value of an attribute.
|
|
337
|
-
*
|
|
338
|
-
* @param {object} obj
|
|
339
|
-
* @param {string} attr
|
|
340
|
-
* @return {*}
|
|
341
|
-
*/
|
|
342
|
-
_getAttr(obj, attr)
|
|
343
|
-
{
|
|
344
|
-
return obj[attr];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* This will get a property value or the model data.
|
|
349
|
-
*
|
|
350
|
-
* @param {string} [attrName]
|
|
351
|
-
* @return {*}
|
|
352
|
-
*/
|
|
353
|
-
get(attrName)
|
|
354
|
-
{
|
|
355
|
-
if(typeof attrName !== 'undefined')
|
|
356
|
-
{
|
|
357
|
-
return this._getAttr(this.stage, attrName);
|
|
358
|
-
}
|
|
359
|
-
else
|
|
360
|
-
{
|
|
361
|
-
return this.getModelData();
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* This will link a data source property to another data source.
|
|
367
|
-
*
|
|
368
|
-
* @param {object} data
|
|
369
|
-
* @param {string|object} attr
|
|
370
|
-
* @param {string} alias
|
|
371
|
-
* @return {string|array}
|
|
372
|
-
*/
|
|
373
|
-
link(data, attr, alias)
|
|
374
|
-
{
|
|
375
|
-
// this will get the data source attrs if sending a whole data object
|
|
376
|
-
if(arguments.length === 1 && data.isData === true)
|
|
377
|
-
{
|
|
378
|
-
attr = data.get();
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
if(typeof attr !== 'object')
|
|
382
|
-
{
|
|
383
|
-
return this.remoteLink(data, attr, alias);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
let tokens = [];
|
|
387
|
-
for(var prop in attr)
|
|
388
|
-
{
|
|
389
|
-
if(attr.hasOwnProperty(prop) === false)
|
|
390
|
-
{
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
tokens.push(this.remoteLink(data, prop));
|
|
395
|
-
}
|
|
396
|
-
return tokens;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* This will link a remote data source by property.
|
|
401
|
-
*
|
|
402
|
-
* @param {object} data
|
|
403
|
-
* @param {string} attr
|
|
404
|
-
* @param {string} alias
|
|
405
|
-
* @return {string}
|
|
406
|
-
*/
|
|
407
|
-
remoteLink(data, attr, alias)
|
|
408
|
-
{
|
|
409
|
-
let childAttr = alias || attr;
|
|
410
|
-
let value = data.get(attr);
|
|
411
|
-
if(typeof value !== 'undefined' && this.get(attr) !== value)
|
|
412
|
-
{
|
|
413
|
-
this.set(attr, value);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
let token = data.on(attr, (propValue, committer) =>
|
|
417
|
-
{
|
|
418
|
-
if(committer === this)
|
|
419
|
-
{
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
this.set(childAttr, propValue, data);
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
this.addLink(token, data);
|
|
427
|
-
|
|
428
|
-
let remoteToken = this.on(childAttr, (propValue, committer) =>
|
|
429
|
-
{
|
|
430
|
-
if(committer === data)
|
|
431
|
-
{
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
data.set(attr, propValue, this);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
data.addLink(remoteToken, this);
|
|
439
|
-
return token;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* This will add a link token to the links array.
|
|
444
|
-
*
|
|
445
|
-
* @param {string} token
|
|
446
|
-
* @param {object} data
|
|
447
|
-
*/
|
|
448
|
-
addLink(token, data)
|
|
449
|
-
{
|
|
450
|
-
this.links[token] = data;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* This will remove a link or all links.
|
|
455
|
-
*
|
|
456
|
-
* @param {string} [token]
|
|
457
|
-
*/
|
|
458
|
-
unlink(token)
|
|
459
|
-
{
|
|
460
|
-
if(token)
|
|
461
|
-
{
|
|
462
|
-
this.removeLink(token);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
let links = this.links;
|
|
467
|
-
if(links.length)
|
|
468
|
-
{
|
|
469
|
-
for(var i = 0, length = links.length; i < length; i++)
|
|
470
|
-
{
|
|
471
|
-
this.removeLink(links[i], false);
|
|
472
|
-
}
|
|
473
|
-
this.links = [];
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* This will remove the linked subscription.
|
|
479
|
-
*
|
|
480
|
-
* @param {string} token
|
|
481
|
-
* @param {bool} removeFromLinks
|
|
482
|
-
*/
|
|
483
|
-
removeLink(token, removeFromLinks)
|
|
484
|
-
{
|
|
485
|
-
let data = this.links[token];
|
|
486
|
-
if(data)
|
|
487
|
-
{
|
|
488
|
-
data.off(token);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if(removeFromLinks === false)
|
|
492
|
-
{
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
delete this.links[token];
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
BasicData.prototype.isData = true;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const DataUtils =
|
|
2
|
-
{
|
|
3
|
-
/**
|
|
4
|
-
* @param {RexExp} deepDataPattern
|
|
5
|
-
*/
|
|
6
|
-
deepDataPattern: /(\w+)|(?:\[(\d)\))/g,
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* This will check if a string has deep data.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} str
|
|
12
|
-
* @return {bool}
|
|
13
|
-
*/
|
|
14
|
-
hasDeepData(str)
|
|
15
|
-
{
|
|
16
|
-
return (str.indexOf('.') !== -1 || str.indexOf('[') !== -1);
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* This will get the deep data segments
|
|
21
|
-
* @param {string} str
|
|
22
|
-
* @return {array}
|
|
23
|
-
*/
|
|
24
|
-
getSegments(str)
|
|
25
|
-
{
|
|
26
|
-
var pattern = this.deepDataPattern;
|
|
27
|
-
return str.match(pattern);
|
|
28
|
-
}
|
|
29
|
-
};
|
package/es6/modules/data/data.js
DELETED