@base-framework/base 2.6.0 → 2.6.1
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/base.min.js +1 -0
- package/es5/base.js +2968 -0
- package/es5/modules/ajax.js +663 -0
- package/es5/modules/animation.js +188 -0
- package/es5/modules/animations.js +1080 -0
- package/es5/modules/atom.js +65 -0
- package/es5/modules/component.js +1310 -0
- package/es5/modules/data-binder.js +1131 -0
- package/es5/modules/data.js +1808 -0
- package/es5/modules/date.js +525 -0
- package/es5/modules/form-validator.js +324 -0
- package/es5/modules/history.js +126 -0
- package/es5/modules/html-builder.js +461 -0
- package/es5/modules/layout.js +1679 -0
- package/es5/modules/mouse.js +124 -0
- package/es5/modules/nav-link.js +123 -0
- package/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es5/modules/olderversions/animations-update.js +1048 -0
- package/es5/modules/olderversions/base-animations.js +636 -0
- package/es5/modules/olderversions/base-component-class.js +100 -0
- package/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es5/modules/olderversions/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es5/modules/olderversions/data-tracker.js +187 -0
- package/es5/modules/olderversions/event-update.js +666 -0
- package/es5/modules/olderversions/nav-link.js +119 -0
- package/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es5/modules/prototypes/ajax.js +657 -0
- package/es5/modules/prototypes/atom.js +65 -0
- package/es5/modules/prototypes/component.js +972 -0
- package/es5/modules/prototypes/data-binder.js +1089 -0
- package/es5/modules/prototypes/data.js +1290 -0
- package/es5/modules/prototypes/html-builder.js +414 -0
- package/es5/modules/prototypes/layout.js +879 -0
- package/es5/modules/router.js +1680 -0
- package/es5/modules/state.js +274 -0
- package/es6/.jshintrc +3 -0
- package/es6/base.js +41 -0
- package/es6/core.js +1 -0
- package/es6/data-tracker.js +351 -0
- package/es6/events.js +602 -0
- package/es6/legacy/es5/base.js +2968 -0
- package/es6/legacy/es5/modules/ajax.js +663 -0
- package/es6/legacy/es5/modules/animation.js +188 -0
- package/es6/legacy/es5/modules/animations.js +1080 -0
- package/es6/legacy/es5/modules/atom.js +65 -0
- package/es6/legacy/es5/modules/component.js +1310 -0
- package/es6/legacy/es5/modules/data-binder.js +1131 -0
- package/es6/legacy/es5/modules/data.js +1808 -0
- package/es6/legacy/es5/modules/date.js +525 -0
- package/es6/legacy/es5/modules/form-validator.js +324 -0
- package/es6/legacy/es5/modules/history.js +126 -0
- package/es6/legacy/es5/modules/html-builder.js +461 -0
- package/es6/legacy/es5/modules/layout.js +1679 -0
- package/es6/legacy/es5/modules/mouse.js +124 -0
- package/es6/legacy/es5/modules/nav-link.js +123 -0
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
- package/es6/legacy/es5/modules/prototypes/component.js +972 -0
- package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
- package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
- package/es6/legacy/es5/modules/router.js +1680 -0
- package/es6/legacy/es5/modules/state.js +274 -0
- package/es6/main.js +1331 -0
- package/es6/modules/ajax/ajax.js +514 -0
- package/es6/modules/animation/animation.js +236 -0
- package/es6/modules/animations/animation-controller.js +231 -0
- package/es6/modules/animations/animation.js +64 -0
- package/es6/modules/animations/attr-movement.js +66 -0
- package/es6/modules/animations/css-movement.js +170 -0
- package/es6/modules/animations/movement.js +131 -0
- package/es6/modules/animations/value.js +187 -0
- package/es6/modules/atom/atom.js +54 -0
- package/es6/modules/component/component.js +230 -0
- package/es6/modules/component/event-helper.js +119 -0
- package/es6/modules/component/jot.js +144 -0
- package/es6/modules/component/state-helper.js +262 -0
- package/es6/modules/component/unit.js +551 -0
- package/es6/modules/data/attrs.js +40 -0
- package/es6/modules/data/basic-data.js +500 -0
- package/es6/modules/data/data-utils.js +29 -0
- package/es6/modules/data/data.js +3 -0
- package/es6/modules/data/deep-data.js +541 -0
- package/es6/modules/data/model-service.js +528 -0
- package/es6/modules/data/model.js +133 -0
- package/es6/modules/data/simple-data.js +33 -0
- package/es6/modules/data-binder/connection-tracker.js +113 -0
- package/es6/modules/data-binder/connection.js +16 -0
- package/es6/modules/data-binder/data-binder.js +352 -0
- package/es6/modules/data-binder/data-pub-sub.js +141 -0
- package/es6/modules/data-binder/data-source.js +56 -0
- package/es6/modules/data-binder/element-source.js +219 -0
- package/es6/modules/data-binder/one-way-connection.js +46 -0
- package/es6/modules/data-binder/one-way-source.js +43 -0
- package/es6/modules/data-binder/source.js +36 -0
- package/es6/modules/data-binder/two-way-connection.js +75 -0
- package/es6/modules/data-binder/two-way-source.js +41 -0
- package/es6/modules/date/date.js +544 -0
- package/es6/modules/history/history.js +89 -0
- package/es6/modules/html-builder/html-builder.js +434 -0
- package/es6/modules/import/import.js +390 -0
- package/es6/modules/layout/layout-builder.js +1269 -0
- package/es6/modules/layout/layout-parser.js +134 -0
- package/es6/modules/layout/watcher-helper.js +282 -0
- package/es6/modules/mouse/mouse.js +114 -0
- package/es6/modules/router/component-helper.js +163 -0
- package/es6/modules/router/history-controller.js +216 -0
- package/es6/modules/router/nav-link.js +124 -0
- package/es6/modules/router/route.js +401 -0
- package/es6/modules/router/router.js +789 -0
- package/es6/modules/router/utils.js +31 -0
- package/es6/modules/state/state-target.js +91 -0
- package/es6/modules/state/state.js +171 -0
- package/es6/package-lock.json +13 -0
- package/es6/package.json +28 -0
- package/es6/shared/objects.js +99 -0
- package/legacy/es5/base.js +2968 -0
- package/legacy/es5/modules/ajax.js +663 -0
- package/legacy/es5/modules/animation.js +188 -0
- package/legacy/es5/modules/animations.js +1080 -0
- package/legacy/es5/modules/atom.js +65 -0
- package/legacy/es5/modules/component.js +1310 -0
- package/legacy/es5/modules/data-binder.js +1131 -0
- package/legacy/es5/modules/data.js +1808 -0
- package/legacy/es5/modules/date.js +525 -0
- package/legacy/es5/modules/form-validator.js +324 -0
- package/legacy/es5/modules/history.js +126 -0
- package/legacy/es5/modules/html-builder.js +461 -0
- package/legacy/es5/modules/layout.js +1679 -0
- package/legacy/es5/modules/mouse.js +124 -0
- package/legacy/es5/modules/nav-link.js +123 -0
- package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/legacy/es5/modules/prototypes/atom.js +65 -0
- package/legacy/es5/modules/prototypes/component.js +972 -0
- package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/legacy/es5/modules/prototypes/data.js +1290 -0
- package/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/legacy/es5/modules/prototypes/layout.js +879 -0
- package/legacy/es5/modules/router.js +1680 -0
- package/legacy/es5/modules/state.js +274 -0
- package/package.json +8 -3
- package/update +16 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {base} from '../../core.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ConnectionTracker
|
|
5
|
+
*
|
|
6
|
+
* This will create a new connection tracker to track active
|
|
7
|
+
* connections in the data binder.
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export class ConnectionTracker
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* @constructor
|
|
14
|
+
*/
|
|
15
|
+
constructor()
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* @member {object} connections
|
|
19
|
+
*/
|
|
20
|
+
this.connections = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This will add a new connection to be tracked.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} id
|
|
27
|
+
* @param {string} attr
|
|
28
|
+
* @param {object} connection
|
|
29
|
+
* @return {object}
|
|
30
|
+
*/
|
|
31
|
+
add(id, attr, connection)
|
|
32
|
+
{
|
|
33
|
+
let connections = this.find(id);
|
|
34
|
+
return (connections[attr] = connection);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This will get a connection.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} id
|
|
41
|
+
* @param {string} attr
|
|
42
|
+
* @return {(object|bool)}
|
|
43
|
+
*/
|
|
44
|
+
get(id, attr)
|
|
45
|
+
{
|
|
46
|
+
let connections = this.connections[id];
|
|
47
|
+
if(connections)
|
|
48
|
+
{
|
|
49
|
+
return (connections[attr] || false);
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* This will find a connection.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} id
|
|
58
|
+
* @return {object}
|
|
59
|
+
*/
|
|
60
|
+
find(id)
|
|
61
|
+
{
|
|
62
|
+
let connections = this.connections;
|
|
63
|
+
return (connections[id] || (connections[id] = {}));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This will remove a connection or all connections by id.
|
|
68
|
+
* @param {string} id
|
|
69
|
+
* @param {string} [attr]
|
|
70
|
+
*/
|
|
71
|
+
remove(id, attr)
|
|
72
|
+
{
|
|
73
|
+
let connections = this.connections[id];
|
|
74
|
+
if(!connections)
|
|
75
|
+
{
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let connection;
|
|
80
|
+
if(attr)
|
|
81
|
+
{
|
|
82
|
+
connection = connections[attr];
|
|
83
|
+
if(connection)
|
|
84
|
+
{
|
|
85
|
+
connection.unsubscribe();
|
|
86
|
+
delete connections[attr];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* this will remove the msg from the elements
|
|
90
|
+
if no elements are listed under the msg */
|
|
91
|
+
if(base.isEmpty(connections))
|
|
92
|
+
{
|
|
93
|
+
delete this.connections[id];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
{
|
|
98
|
+
for(var prop in connections)
|
|
99
|
+
{
|
|
100
|
+
if(connections.hasOwnProperty(prop))
|
|
101
|
+
{
|
|
102
|
+
connection = connections[prop];
|
|
103
|
+
if(connection)
|
|
104
|
+
{
|
|
105
|
+
connection.unsubscribe();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
delete this.connections[id];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import {base} from '../../core.js';
|
|
2
|
+
export {DataPubSub} from './data-pub-sub.js';
|
|
3
|
+
import {pubSub} from './data-pub-sub.js';
|
|
4
|
+
import {OneWayConnection} from './one-way-connection.js';
|
|
5
|
+
import {TwoWayConnection} from './two-way-connection.js';
|
|
6
|
+
import {ConnectionTracker} from './connection-tracker.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* DataBinder
|
|
10
|
+
*
|
|
11
|
+
* This will create a data binder object that can
|
|
12
|
+
* create one way and two way data bindings.
|
|
13
|
+
* @class
|
|
14
|
+
*/
|
|
15
|
+
export class DataBinder
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* @constructor
|
|
19
|
+
*/
|
|
20
|
+
constructor()
|
|
21
|
+
{
|
|
22
|
+
this.version = "1.0.1";
|
|
23
|
+
this.attr = 'bindId';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @member {array} blockedKeys
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
this.blockedKeys = [
|
|
30
|
+
20, //caps lock
|
|
31
|
+
37, //arrows
|
|
32
|
+
38,
|
|
33
|
+
39,
|
|
34
|
+
40
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
this.connections = new ConnectionTracker();
|
|
38
|
+
|
|
39
|
+
this.idCount = 0;
|
|
40
|
+
this.setup();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* This will setup the events.
|
|
45
|
+
* @protected
|
|
46
|
+
*/
|
|
47
|
+
setup()
|
|
48
|
+
{
|
|
49
|
+
this.setupEvents();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This will bind an element to a data property.
|
|
54
|
+
*
|
|
55
|
+
* @param {object} element
|
|
56
|
+
* @param {object} data
|
|
57
|
+
* @param {string} prop
|
|
58
|
+
* @param {(string|function)} [filter]
|
|
59
|
+
* @return {object} an instance of the databinder.
|
|
60
|
+
*/
|
|
61
|
+
bind(element, data, prop, filter)
|
|
62
|
+
{
|
|
63
|
+
let bindProp = prop,
|
|
64
|
+
bindAttr = null;
|
|
65
|
+
|
|
66
|
+
if(prop.indexOf(':') !== -1)
|
|
67
|
+
{
|
|
68
|
+
/* this will setup the custom attr if the prop
|
|
69
|
+
has specified one. */
|
|
70
|
+
let parts = prop.split(':');
|
|
71
|
+
if(parts.length > 1)
|
|
72
|
+
{
|
|
73
|
+
bindProp = parts[1];
|
|
74
|
+
bindAttr = parts[0];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* this will setup the model bind attr to the
|
|
79
|
+
element and assign a bind id attr to support
|
|
80
|
+
two way binding */
|
|
81
|
+
let connection = this.setupConnection(element, data, bindProp, bindAttr, filter);
|
|
82
|
+
|
|
83
|
+
/* we want to get the starting value of the
|
|
84
|
+
data and set it on our element */
|
|
85
|
+
let connectionElement = connection.element,
|
|
86
|
+
value = data.get(bindProp);
|
|
87
|
+
if(typeof value !== 'undefined')
|
|
88
|
+
{
|
|
89
|
+
connectionElement.set(value);
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
{
|
|
93
|
+
/* this will set the element value
|
|
94
|
+
as the prop value */
|
|
95
|
+
value = connectionElement.get();
|
|
96
|
+
if(value !== '')
|
|
97
|
+
{
|
|
98
|
+
connection.data.set(value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* This will bind an element to a data property.
|
|
106
|
+
*
|
|
107
|
+
* @protected
|
|
108
|
+
* @param {object} element
|
|
109
|
+
* @param {object} data
|
|
110
|
+
* @param {string} prop
|
|
111
|
+
* @param {string} customAttr
|
|
112
|
+
* @param {(string|function)} [filter]
|
|
113
|
+
* @return {object} The new connection.
|
|
114
|
+
*/
|
|
115
|
+
setupConnection(element, data, prop, customAttr, filter)
|
|
116
|
+
{
|
|
117
|
+
let id = this.getBindId(element),
|
|
118
|
+
connection = new TwoWayConnection(),
|
|
119
|
+
|
|
120
|
+
// this will create the data source
|
|
121
|
+
dataSource = connection.addData(data, prop);
|
|
122
|
+
// this will subscribe the data to the element
|
|
123
|
+
dataSource.subscribe(id);
|
|
124
|
+
|
|
125
|
+
/* this will add the data binding
|
|
126
|
+
attr to our element so it will subscribe to
|
|
127
|
+
the two data changes */
|
|
128
|
+
let dataId = data.getDataId(),
|
|
129
|
+
msg = dataId + ':' + prop;
|
|
130
|
+
|
|
131
|
+
// this will create the element source
|
|
132
|
+
let elementSource = connection.addElement(element, customAttr, filter);
|
|
133
|
+
// this will subscribe the element to the data
|
|
134
|
+
elementSource.subscribe(msg);
|
|
135
|
+
|
|
136
|
+
this.addConnection(id, 'bind', connection);
|
|
137
|
+
|
|
138
|
+
return connection;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* This will add a new connection to the
|
|
143
|
+
* connection tracker.
|
|
144
|
+
*
|
|
145
|
+
* @protected
|
|
146
|
+
* @param {string} id
|
|
147
|
+
* @param {string} attr
|
|
148
|
+
* @param {object} connection
|
|
149
|
+
*/
|
|
150
|
+
addConnection(id, attr, connection)
|
|
151
|
+
{
|
|
152
|
+
this.connections.add(id, attr, connection);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* This will set the bind id.
|
|
157
|
+
*
|
|
158
|
+
* @param {object} element
|
|
159
|
+
*/
|
|
160
|
+
setBindId(element)
|
|
161
|
+
{
|
|
162
|
+
let id = 'db-' + this.idCount++;
|
|
163
|
+
element.dataset[this.attr] = id;
|
|
164
|
+
element[this.attr] = id;
|
|
165
|
+
return id;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* This will get the bind id.
|
|
170
|
+
*
|
|
171
|
+
* @param {object} element
|
|
172
|
+
* @return {string}
|
|
173
|
+
*/
|
|
174
|
+
getBindId(element)
|
|
175
|
+
{
|
|
176
|
+
return element[this.attr] || this.setBindId(element);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* This will unbind the element.
|
|
181
|
+
*
|
|
182
|
+
* @param {object} element
|
|
183
|
+
* @return {object} an instance of the data binder.
|
|
184
|
+
*/
|
|
185
|
+
unbind(element)
|
|
186
|
+
{
|
|
187
|
+
let id = element[this.attr];
|
|
188
|
+
if(id)
|
|
189
|
+
{
|
|
190
|
+
this.connections.remove(id);
|
|
191
|
+
}
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* This will setup a watcher for an element.
|
|
197
|
+
*
|
|
198
|
+
* @param {object} element
|
|
199
|
+
* @param {object} data
|
|
200
|
+
* @param {string} prop
|
|
201
|
+
* @param {function} callBack
|
|
202
|
+
*/
|
|
203
|
+
watch(element, data, prop, callBack)
|
|
204
|
+
{
|
|
205
|
+
if(!element || typeof element !== 'object')
|
|
206
|
+
{
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let connection = new OneWayConnection();
|
|
211
|
+
|
|
212
|
+
// this will create the one way source
|
|
213
|
+
const source = connection.addSource(data);
|
|
214
|
+
source.subscribe(prop, callBack);
|
|
215
|
+
|
|
216
|
+
// this will add the new connection to the connection tracker
|
|
217
|
+
const id = this.getBindId(element),
|
|
218
|
+
attr = data.getDataId() + ':' + prop;
|
|
219
|
+
this.addConnection(id, attr, connection);
|
|
220
|
+
|
|
221
|
+
let value = data.get(prop);
|
|
222
|
+
if(typeof value !== 'undefined')
|
|
223
|
+
{
|
|
224
|
+
callBack(value);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* This will remove a watcher from an element.
|
|
230
|
+
*
|
|
231
|
+
* @param {object} element
|
|
232
|
+
* @param {object} data
|
|
233
|
+
* @param {string} prop
|
|
234
|
+
*/
|
|
235
|
+
unwatch(element, data, prop)
|
|
236
|
+
{
|
|
237
|
+
if(!element || typeof element !== 'object')
|
|
238
|
+
{
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let id = element[this.attr];
|
|
243
|
+
if(id)
|
|
244
|
+
{
|
|
245
|
+
let attr = data.getDataId() + ':' + prop;
|
|
246
|
+
this.connections.remove(id, attr);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* This will publish to the pub sub.
|
|
252
|
+
*
|
|
253
|
+
* @param {string} msg
|
|
254
|
+
* @param {*} value
|
|
255
|
+
* @param {object} committer
|
|
256
|
+
* @return {object} an instance of the data binder.
|
|
257
|
+
*/
|
|
258
|
+
publish(msg, value, committer)
|
|
259
|
+
{
|
|
260
|
+
pubSub.publish(msg, value, committer);
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* This will check if an element is bound.
|
|
266
|
+
*
|
|
267
|
+
* @protected
|
|
268
|
+
* @param {object} element
|
|
269
|
+
* @return {boolean}
|
|
270
|
+
*/
|
|
271
|
+
isDataBound(element)
|
|
272
|
+
{
|
|
273
|
+
if(element)
|
|
274
|
+
{
|
|
275
|
+
let id = element[this.attr];
|
|
276
|
+
if(id)
|
|
277
|
+
{
|
|
278
|
+
return id;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
isBlocked(evt)
|
|
285
|
+
{
|
|
286
|
+
if(evt.type !== 'keyup')
|
|
287
|
+
{
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* this will check to block ctrl, shift or alt +
|
|
292
|
+
buttons */
|
|
293
|
+
return (this.blockedKeys.indexOf(evt.keyCode) !== -1);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* This is the callBack for the chnage event.
|
|
298
|
+
*
|
|
299
|
+
* @param {object} evt
|
|
300
|
+
*/
|
|
301
|
+
bindHandler(evt)
|
|
302
|
+
{
|
|
303
|
+
if(this.isBlocked(evt))
|
|
304
|
+
{
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
let target = evt.target || evt.srcElement,
|
|
309
|
+
id = this.isDataBound(target);
|
|
310
|
+
if(id)
|
|
311
|
+
{
|
|
312
|
+
let connection = this.connections.get(id, 'bind');
|
|
313
|
+
if(connection)
|
|
314
|
+
{
|
|
315
|
+
let value = connection.element.get();
|
|
316
|
+
/* this will publish to the ui and to the
|
|
317
|
+
model that subscribes to the element */
|
|
318
|
+
pubSub.publish(id, value, target);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
evt.stopPropagation();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* This wil setup the events.
|
|
326
|
+
* @protected
|
|
327
|
+
*/
|
|
328
|
+
setupEvents()
|
|
329
|
+
{
|
|
330
|
+
this.changeHandler = this.bindHandler.bind(this);
|
|
331
|
+
|
|
332
|
+
this.addEvents();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* This will add the events.
|
|
337
|
+
*/
|
|
338
|
+
addEvents()
|
|
339
|
+
{
|
|
340
|
+
base.on(["change", "keyup"], document, this.changeHandler, false);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* This will remove the events.
|
|
345
|
+
*/
|
|
346
|
+
removeEvents()
|
|
347
|
+
{
|
|
348
|
+
base.off(["change", "keyup"], document, this.changeHandler, false);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export const dataBinder = new DataBinder();
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
let lastToken = -1;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DataPubSub
|
|
5
|
+
*
|
|
6
|
+
* This is a pub sub class to allow subscribers to
|
|
7
|
+
* listen for updates when published by publishers.
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export class DataPubSub
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* @constructor
|
|
14
|
+
*/
|
|
15
|
+
constructor()
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* @member {object} callBacks
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
this.callBacks = {};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @member {int} lastToken
|
|
25
|
+
* @protected
|
|
26
|
+
*/
|
|
27
|
+
this.lastToken = -1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This will get a subscriber array.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} msg
|
|
34
|
+
* @return {array}
|
|
35
|
+
*/
|
|
36
|
+
get(msg)
|
|
37
|
+
{
|
|
38
|
+
let callBacks = this.callBacks;
|
|
39
|
+
return (callBacks[msg] || (callBacks[msg] = []));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This will reset pub sub.
|
|
44
|
+
*/
|
|
45
|
+
reset()
|
|
46
|
+
{
|
|
47
|
+
this.callBacks = {};
|
|
48
|
+
this.lastToken = -1;
|
|
49
|
+
lastToken = -1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This will add a subscriber.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} msg
|
|
56
|
+
* @param {function} callBack
|
|
57
|
+
* @return {string} The subscriber token.
|
|
58
|
+
*/
|
|
59
|
+
on(msg, callBack)
|
|
60
|
+
{
|
|
61
|
+
let token = (++lastToken),
|
|
62
|
+
list = this.get(msg);
|
|
63
|
+
list.push({
|
|
64
|
+
token: token,
|
|
65
|
+
callBack: callBack
|
|
66
|
+
});
|
|
67
|
+
return token;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* This will remove a subscriber.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} msg
|
|
74
|
+
* @param {string} token
|
|
75
|
+
*/
|
|
76
|
+
off(msg, token)
|
|
77
|
+
{
|
|
78
|
+
let list = this.callBacks[msg] || false;
|
|
79
|
+
if(list === false)
|
|
80
|
+
{
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let length = list.length;
|
|
85
|
+
for (var i = 0; i < length; i++ )
|
|
86
|
+
{
|
|
87
|
+
var item = list[i];
|
|
88
|
+
if(item.token === token)
|
|
89
|
+
{
|
|
90
|
+
list.splice(i, 1);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* This will delete a message.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} msg
|
|
100
|
+
*/
|
|
101
|
+
remove(msg)
|
|
102
|
+
{
|
|
103
|
+
let callBacks = this.callBacks;
|
|
104
|
+
if(callBacks[msg])
|
|
105
|
+
{
|
|
106
|
+
delete callBacks[msg];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* This will publish a message.
|
|
112
|
+
*
|
|
113
|
+
* @param {string} msg
|
|
114
|
+
* @param {string} value
|
|
115
|
+
* @param {object} committer
|
|
116
|
+
*/
|
|
117
|
+
publish(msg)
|
|
118
|
+
{
|
|
119
|
+
let i, length,
|
|
120
|
+
list = this.callBacks[msg] || false;
|
|
121
|
+
if(list === false)
|
|
122
|
+
{
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let args = Array.prototype.slice.call(arguments, 1);
|
|
127
|
+
|
|
128
|
+
length = list.length;
|
|
129
|
+
for (i = 0; i < length; i++)
|
|
130
|
+
{
|
|
131
|
+
var item = list[i];
|
|
132
|
+
if(!item)
|
|
133
|
+
{
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
item.callBack.apply(this, args);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const pubSub = new DataPubSub();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {TwoWaySource} from './two-way-source.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DataSource
|
|
5
|
+
*
|
|
6
|
+
* This will create a data source to use with
|
|
7
|
+
* a connection.
|
|
8
|
+
* @class
|
|
9
|
+
* @augments TwoWaySource
|
|
10
|
+
*/
|
|
11
|
+
export class DataSource extends TwoWaySource
|
|
12
|
+
{
|
|
13
|
+
/**
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {object} data
|
|
16
|
+
* @param {string} prop
|
|
17
|
+
*/
|
|
18
|
+
constructor(data, prop)
|
|
19
|
+
{
|
|
20
|
+
super();
|
|
21
|
+
this.data = data;
|
|
22
|
+
this.prop = prop;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This will set the data value.
|
|
27
|
+
*
|
|
28
|
+
* @param {*} value
|
|
29
|
+
*/
|
|
30
|
+
set(value)
|
|
31
|
+
{
|
|
32
|
+
this.data.set(this.prop, value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This will get the data value.
|
|
37
|
+
*/
|
|
38
|
+
get()
|
|
39
|
+
{
|
|
40
|
+
return this.data.get(this.prop);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The callBack when updated.
|
|
45
|
+
*
|
|
46
|
+
* @param {*} value
|
|
47
|
+
* @param {object} committer
|
|
48
|
+
*/
|
|
49
|
+
callBack(value, committer)
|
|
50
|
+
{
|
|
51
|
+
if(this.data !== committer)
|
|
52
|
+
{
|
|
53
|
+
this.data.set(this.prop, value, committer);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|