@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.
Files changed (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +30 -26
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
@@ -1,274 +0,0 @@
1
- /* base framework module */
2
- /*
3
- this will create a layout builder object
4
- and shortcut functions.
5
- */
6
- (function()
7
- {
8
- "use strict";
9
-
10
- /**
11
- * StateTarget
12
- *
13
- * This will create a state target to track the state
14
- * of an object.
15
- * @class
16
- * @augments base.SimpleData
17
- */
18
- var StateTarget = base.SimpleData.extend(
19
- {
20
- /**
21
- * @constructor
22
- * @param {string} id
23
- */
24
- constructor: function(id)
25
- {
26
- this._init();
27
-
28
- /* this will setup the event sub for
29
- one way binding */
30
- this.eventSub = new base.DataPubSub();
31
-
32
- this.links = {};
33
- this.stage = {};
34
- this.id = id;
35
- },
36
-
37
- /**
38
- * This will restore a state to the controller.
39
- */
40
- restore: function()
41
- {
42
- base.state.restore(this.id, this);
43
- },
44
-
45
- /**
46
- * This will remove the target from the controller.
47
- */
48
- remove: function()
49
- {
50
- base.state.remove(this.id);
51
- },
52
-
53
- /**
54
- * This will add an action to the target.
55
- *
56
- * @param {string} action
57
- * @param {*} state
58
- */
59
- addAction: function(action, state)
60
- {
61
- if(typeof state !== 'undefined')
62
- {
63
- this.set(action, state);
64
- }
65
- },
66
-
67
- /**
68
- * This will get the state of an action.
69
- *
70
- * @param {string} action
71
- * @return {*}
72
- */
73
- getState: function(action)
74
- {
75
- return this.get(action);
76
- },
77
-
78
- /**
79
- * This will remove an action or a callBack
80
- * from an action. if no token is passed the
81
- * whole action is removed.
82
- *
83
- * @param {string} action
84
- * @param {string} [token]
85
- */
86
- removeAction: function(action, token)
87
- {
88
- /* if we have a token then the token will be
89
- the only item removed */
90
- if(token)
91
- {
92
- this.off(action, token);
93
- }
94
- else
95
- {
96
- var actions = this.stage;
97
- if(typeof actions[action] !== 'undefined')
98
- {
99
- delete actions[action];
100
- }
101
- }
102
- }
103
- });
104
-
105
- /**
106
- * StateController
107
- *
108
- * This will create a state controller that can
109
- * add and remove targets, actions, and action
110
- * subscriber callBack functions.
111
- *
112
- * @class
113
- */
114
- var StateController = base.Class.extend(
115
- {
116
- /**
117
- * @constructor
118
- */
119
- constructor: function()
120
- {
121
- this.targets = {};
122
- },
123
-
124
- /**
125
- * This will restore a state target.
126
- *
127
- * @param {string} id
128
- * @param {object} target
129
- */
130
- restore: function(id, target)
131
- {
132
- this.targets[id] = target;
133
- },
134
-
135
- /**
136
- * This will get the state target.
137
- *
138
- * @param {string} id
139
- * @return {object}
140
- */
141
- getTarget: function(id)
142
- {
143
- var targets = this.targets;
144
- return (targets[id] || (targets[id] = new StateTarget(id)));
145
- },
146
-
147
- /**
148
- * This will get the state of an action.
149
- *
150
- * @param {string} targetId
151
- * @param {string} action
152
- */
153
- getActionState: function(targetId, action)
154
- {
155
- var target = this.getTarget(targetId);
156
- return target.get(action);
157
- },
158
-
159
- /**
160
- * This will add a new target.
161
- *
162
- * @param {string} targetId
163
- * @param {string} [action]
164
- * @param {*} [state] the primary action state
165
- * @return {object}
166
- */
167
- add: function(targetId, action, state)
168
- {
169
- var target = this.getTarget(targetId);
170
- if(action)
171
- {
172
- target.addAction(action, state);
173
- }
174
- return target;
175
- },
176
-
177
- /**
178
- * This will add a new action to a target.
179
- *
180
- * @param {string} targetId
181
- * @param {string} action
182
- * @param {string} [state]
183
- * @return {object}
184
- */
185
- addAction: function(targetId, action, state)
186
- {
187
- return this.add(targetId, action, state);
188
- },
189
-
190
- /**
191
- * This will remove the action from a target.
192
- *
193
- * @param {string} targetId
194
- * @param {string} action
195
- * @param {string} [token]
196
- */
197
- removeAction: function(targetId, action, token)
198
- {
199
- this.off(targetId, action, token);
200
- },
201
-
202
- /**
203
- * This will add a new subscriber to the action.
204
- *
205
- * @param {string} targetId
206
- * @param {string} action
207
- * @param {function} callBack
208
- * @return {string}
209
- */
210
- on: function(targetId, action, callBack)
211
- {
212
- var target = this.getTarget(targetId);
213
- if(action)
214
- {
215
- return target.on(action, callBack);
216
- }
217
- return false;
218
- },
219
-
220
- /**
221
- * This will remove a subscriber from an action.
222
- *
223
- * @param {string} targetId
224
- * @param {string} action
225
- * @param {string} token
226
- */
227
- off: function(targetId, action, token)
228
- {
229
- this.remove(targetId, action, token);
230
- },
231
-
232
- /**
233
- * This will remove a target or action or callBack.
234
- *
235
- * @param {string} targetId
236
- * @param {string} [action]
237
- * @param {string} [token]
238
- */
239
- remove: function(targetId, action, token)
240
- {
241
- var targets = this.targets;
242
- var target = targets[targetId];
243
- if(!target)
244
- {
245
- return false;
246
- }
247
-
248
- if(action)
249
- {
250
- target.off(action, token);
251
- }
252
- else
253
- {
254
- delete targets[targetId];
255
- }
256
- },
257
-
258
- /**
259
- * This will set the action state.
260
- *
261
- * @param {string} targetId
262
- * @param {string} action
263
- * @param {*} state
264
- */
265
- set: function(targetId, action, state)
266
- {
267
- var target = this.getTarget(targetId);
268
- target.set(action, state);
269
- }
270
- });
271
-
272
- base.extend.StateController = StateController;
273
- base.extend.state = new StateController();
274
- })();
package/es6/.jshintrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "esversion": 6
3
- }
package/es6/base.js DELETED
@@ -1,41 +0,0 @@
1
- import {base} from './core.js';
2
- import {ajax} from './modules/ajax/ajax.js';
3
- import {dataBinder} from './modules/data-binder/data-binder.js';
4
- import {Data, SimpleData, Model} from './modules/data/data.js';
5
- import {state} from './modules/state/state.js';
6
- import {router, NavLink} from './modules/router/router.js';
7
- import {builder} from './modules/layout/layout-builder.js';
8
- import {Unit, Component, Jot, Watch} from './modules/component/component.js';
9
- import {Atom} from './modules/atom/atom.js';
10
-
11
- base.augment(
12
- {
13
- ajax,
14
- dataBinder,
15
- Data,
16
- SimpleData,
17
- Model,
18
- state,
19
- builder,
20
- router,
21
- Component
22
- });
23
-
24
- export {
25
- base,
26
- ajax,
27
- dataBinder,
28
- Data,
29
- SimpleData,
30
- Model,
31
- state,
32
- builder,
33
- router,
34
- Unit,
35
- Component,
36
- Jot,
37
- Watch,
38
- NavLink,
39
- Atom
40
- };
41
-
package/es6/core.js DELETED
@@ -1 +0,0 @@
1
- export {base} from './events.js';
@@ -1,351 +0,0 @@
1
- /**
2
- * TrackerTypes
3
- *
4
- * This will add and remove tracker types to the data tracker.
5
- *
6
- */
7
- const TrackerTypes =
8
- {
9
- /**
10
- * @member {object} The Type and callBack that is called
11
- * when the type is removed from the object.
12
- */
13
- types: {},
14
-
15
- /**
16
- * This will add a type.
17
- * @param {string} type
18
- * @param {function} callBack The function to call when an object
19
- * is having the type removed.
20
- */
21
- add(type, callBack)
22
- {
23
- this.types[type] = callBack;
24
- },
25
-
26
- /**
27
- * This will get a type or return false.
28
- * @param {string} type
29
- * @return {(function|boolean)} The callBack or false.
30
- */
31
- get(type)
32
- {
33
- return this.types[type] || false;
34
- },
35
-
36
- /**
37
- * This will remove a type.
38
- * @param {string} type
39
- */
40
- remove(type)
41
- {
42
- delete this.types[type];
43
- }
44
- };
45
-
46
- /**
47
- * Tracker
48
- *
49
- * This will create a tracker for an object that will
50
- * store each type added and the data stored to
51
- * each type.
52
- *
53
- * @class
54
- */
55
- class Tracker
56
- {
57
- /**
58
- * @constructor
59
- */
60
- constructor()
61
- {
62
- /**
63
- * @member {object} types
64
- */
65
- this.types = {};
66
- }
67
-
68
- /**
69
- * This will add data to a type.
70
- *
71
- * @public
72
- * @param {string} addingType The type of data.
73
- * @param {*} data The data to store
74
- */
75
- add(addingType, data)
76
- {
77
- let type = this.types[addingType] || (this.types[addingType] = []);
78
- type.push(data);
79
- }
80
-
81
- /**
82
- * This will get all the data stored to a data type.
83
- * @param {string} type
84
- * @return {*|boolean} the data or false.
85
- */
86
- get(type)
87
- {
88
- return this.types[type] || false;
89
- }
90
-
91
- /**
92
- * This will call the callBack with the data.
93
- *
94
- * @private
95
- * @param {function} callBack
96
- * @param {*} data
97
- */
98
- removeByCallBack(callBack, data)
99
- {
100
- if(typeof callBack === 'function')
101
- {
102
- callBack(data);
103
- }
104
- }
105
-
106
- /**
107
- * This will remove the data by type.
108
- *
109
- * @private
110
- * @param {string} removingType
111
- */
112
- removeType(removingType)
113
- {
114
- let types = this.types;
115
- if(types)
116
- {
117
- let type = types[removingType];
118
- if(type.length)
119
- {
120
- let data,
121
- callBack = TrackerTypes.get(removingType);
122
- for(var i = 0, length = type.length; i < length; i++)
123
- {
124
- data = type[i];
125
- if(data)
126
- {
127
- // this will stop any circular referrences
128
- type[i] = null;
129
-
130
- this.removeByCallBack(callBack, data);
131
- }
132
- }
133
- delete types[type];
134
- }
135
- }
136
- }
137
-
138
- /**
139
- * This will remove the data by type or all if no type is
140
- * set.
141
- *
142
- * @public
143
- * @param {string} [type]
144
- */
145
- remove(type)
146
- {
147
- if(type)
148
- {
149
- this.removeType(type);
150
- }
151
- else
152
- {
153
- let types = this.types;
154
- for(var prop in types)
155
- {
156
- if(types.hasOwnProperty(prop))
157
- {
158
- type = types[prop];
159
- if(!type)
160
- {
161
- continue;
162
- }
163
-
164
- this.removeType(prop);
165
- }
166
- }
167
-
168
- delete this.types;
169
- }
170
- }
171
- }
172
-
173
- /**
174
- * DataTracker
175
- *
176
- * This will add data tracking for objects. The DataTracker is
177
- * a single point where any data can be tracked to an object
178
- * or element. Modules can register types to store their own
179
- * data that can allow the data to be removed when the element
180
- * is removed.
181
- *
182
- * @class
183
- */
184
- export class DataTracker
185
- {
186
- /**
187
- * @constructor
188
- */
189
- constructor()
190
- {
191
- /**
192
- * @private
193
- * @member trackers This is an object that stores all tracker
194
- * objects by tracking id.
195
- */
196
- this.trackers = {};
197
-
198
- /**
199
- * @private
200
- * @member {int} trackingCount
201
- */
202
- this.trackingCount = 0;
203
- }
204
-
205
- /**
206
- * This will add a new type to the data tracker.
207
- *
208
- * @public
209
- * @param {string} type The new type.
210
- * @param {function} callBack The callBack to help clean
211
- * up data when removed.
212
- */
213
- addType(type, callBack)
214
- {
215
- TrackerTypes.add(type, callBack);
216
- }
217
-
218
- /**
219
- * This will remove a type from the data tracker.
220
- * @param {string} type
221
- */
222
- removeType(type)
223
- {
224
- TrackerTypes.remove(type);
225
- }
226
-
227
- /**
228
- * This will get the object tracking id or set it if
229
- * not set.
230
- *
231
- * @param {object} obj
232
- * @return {string}
233
- */
234
- getTrackingId(obj)
235
- {
236
- return obj.trackingId || (obj.trackingId = 'dt' + this.trackingCount++);
237
- }
238
-
239
- /**
240
- * This will add data to an object.
241
- *
242
- * @param {object} obj
243
- * @param {string} type The type name.
244
- * @param {*} data The data to track.
245
- */
246
- add(obj, type, data)
247
- {
248
- const id = this.getTrackingId(obj),
249
- tracker = this.find(id);
250
-
251
- tracker.add(type, data);
252
- }
253
-
254
- /**
255
- * This will get the data from a type or the tracker object
256
- * if type is not set.
257
- *
258
- * @param {object} obj
259
- * @param {string} [type]
260
- * @return {*}
261
- */
262
- get(obj, type)
263
- {
264
- const id = obj.trackingId;
265
- let tracker = this.trackers[id];
266
- if(!tracker)
267
- {
268
- return false;
269
- }
270
-
271
- return (type)? tracker.get(type) : tracker;
272
- }
273
-
274
- /**
275
- * This will get the tracker or create a new tracker
276
- * if no tracker is set.
277
- *
278
- * @param {string} id
279
- * @return {object} The tracker.
280
- */
281
- find(id)
282
- {
283
- let trackers = this.trackers;
284
- return (trackers[id] || (trackers[id] = new Tracker()));
285
- }
286
-
287
- /**
288
- * This will check if an object is empty.
289
- *
290
- * @param {object} obj
291
- * @return {boolean}
292
- */
293
- isEmpty(obj)
294
- {
295
- if(!obj || typeof obj !== 'object')
296
- {
297
- return true;
298
- }
299
-
300
- /* we want to loop through each property and
301
- check if it belongs to the object directly */
302
- for(var key in obj)
303
- {
304
- if(obj.hasOwnProperty(key))
305
- {
306
- return false;
307
- }
308
- }
309
- return true;
310
- }
311
-
312
- /**
313
- * This will remove a type or all data for an object if
314
- * no type is set.
315
- *
316
- * @param {object} obj
317
- * @param {stirng} [type]
318
- */
319
- remove(obj, type)
320
- {
321
- const id = obj.trackingId;
322
- if(!id)
323
- {
324
- return true;
325
- }
326
-
327
- let tracker = this.trackers[id];
328
- if(!tracker)
329
- {
330
- return false;
331
- }
332
-
333
- if(type)
334
- {
335
- tracker.remove(type);
336
-
337
- /* this will remove the msg from the elements
338
- if no elements are listed under the msg */
339
- if(this.isEmpty(tracker.types))
340
- {
341
- delete this.trackers[id];
342
- }
343
- }
344
- else
345
- {
346
- tracker.remove();
347
-
348
- delete this.trackers[id];
349
- }
350
- }
351
- }