@gogocat/data-bind 1.11.0 → 2.0.0
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/.editorconfig +14 -14
- package/.vscode/launch.json +12 -12
- package/CONFIGURATION.md +294 -0
- package/REACTIVE_MODE.md +553 -0
- package/README.md +266 -829
- package/babel.config.json +30 -0
- package/dist/js/_escape.d.ts +14 -0
- package/dist/js/_escape.d.ts.map +1 -0
- package/dist/js/applyBinding.d.ts +11 -0
- package/dist/js/applyBinding.d.ts.map +1 -0
- package/dist/js/attrBinding.d.ts +12 -0
- package/dist/js/attrBinding.d.ts.map +1 -0
- package/dist/js/binder.d.ts +67 -0
- package/dist/js/binder.d.ts.map +1 -0
- package/dist/js/changeBinding.d.ts +19 -0
- package/dist/js/changeBinding.d.ts.map +1 -0
- package/dist/js/commentWrapper.d.ts +39 -0
- package/dist/js/commentWrapper.d.ts.map +1 -0
- package/dist/js/config.d.ts +55 -0
- package/dist/js/config.d.ts.map +1 -0
- package/dist/js/createBindingOption.d.ts +32 -0
- package/dist/js/createBindingOption.d.ts.map +1 -0
- package/dist/js/createEventBinding.d.ts +10 -0
- package/dist/js/createEventBinding.d.ts.map +1 -0
- package/dist/js/cssBinding.d.ts +15 -0
- package/dist/js/cssBinding.d.ts.map +1 -0
- package/dist/js/dataBind.js +2772 -2519
- package/dist/js/dataBind.min.js +8 -1
- package/dist/js/dataBind.min.js.map +1 -1
- package/dist/js/domWalker.d.ts +9 -0
- package/dist/js/domWalker.d.ts.map +1 -0
- package/dist/js/forOfBinding.d.ts +12 -0
- package/dist/js/forOfBinding.d.ts.map +1 -0
- package/dist/js/hoverBinding.d.ts +13 -0
- package/dist/js/hoverBinding.d.ts.map +1 -0
- package/dist/js/ifBinding.d.ts +12 -0
- package/dist/js/ifBinding.d.ts.map +1 -0
- package/dist/js/index.d.ts +10 -0
- package/dist/js/index.d.ts.map +1 -0
- package/dist/js/modelBinding.d.ts +12 -0
- package/dist/js/modelBinding.d.ts.map +1 -0
- package/dist/js/postProcess.d.ts +3 -0
- package/dist/js/postProcess.d.ts.map +1 -0
- package/dist/js/pubSub.d.ts +11 -0
- package/dist/js/pubSub.d.ts.map +1 -0
- package/dist/js/reactiveProxy.d.ts +28 -0
- package/dist/js/reactiveProxy.d.ts.map +1 -0
- package/dist/js/renderForOfBinding.d.ts +8 -0
- package/dist/js/renderForOfBinding.d.ts.map +1 -0
- package/dist/js/renderIfBinding.d.ts +22 -0
- package/dist/js/renderIfBinding.d.ts.map +1 -0
- package/dist/js/renderIteration.d.ts +16 -0
- package/dist/js/renderIteration.d.ts.map +1 -0
- package/dist/js/renderTemplate.d.ts +14 -0
- package/dist/js/renderTemplate.d.ts.map +1 -0
- package/dist/js/renderTemplatesBinding.d.ts +19 -0
- package/dist/js/renderTemplatesBinding.d.ts.map +1 -0
- package/dist/js/showBinding.d.ts +13 -0
- package/dist/js/showBinding.d.ts.map +1 -0
- package/dist/js/switchBinding.d.ts +13 -0
- package/dist/js/switchBinding.d.ts.map +1 -0
- package/dist/js/textBinding.d.ts +13 -0
- package/dist/js/textBinding.d.ts.map +1 -0
- package/dist/js/types/_escape.d.ts +14 -0
- package/dist/js/types/_escape.d.ts.map +1 -0
- package/dist/js/types/applyBinding.d.ts +11 -0
- package/dist/js/types/applyBinding.d.ts.map +1 -0
- package/dist/js/types/attrBinding.d.ts +12 -0
- package/dist/js/types/attrBinding.d.ts.map +1 -0
- package/dist/js/types/binder.d.ts +67 -0
- package/dist/js/types/binder.d.ts.map +1 -0
- package/dist/js/types/changeBinding.d.ts +19 -0
- package/dist/js/types/changeBinding.d.ts.map +1 -0
- package/dist/js/types/commentWrapper.d.ts +39 -0
- package/dist/js/types/commentWrapper.d.ts.map +1 -0
- package/dist/js/types/config.d.ts +55 -0
- package/dist/js/types/config.d.ts.map +1 -0
- package/dist/js/types/createBindingOption.d.ts +32 -0
- package/dist/js/types/createBindingOption.d.ts.map +1 -0
- package/dist/js/types/createEventBinding.d.ts +10 -0
- package/dist/js/types/createEventBinding.d.ts.map +1 -0
- package/dist/js/types/cssBinding.d.ts +15 -0
- package/dist/js/types/cssBinding.d.ts.map +1 -0
- package/dist/js/types/domWalker.d.ts +9 -0
- package/dist/js/types/domWalker.d.ts.map +1 -0
- package/dist/js/types/forOfBinding.d.ts +12 -0
- package/dist/js/types/forOfBinding.d.ts.map +1 -0
- package/dist/js/types/hoverBinding.d.ts +13 -0
- package/dist/js/types/hoverBinding.d.ts.map +1 -0
- package/dist/js/types/ifBinding.d.ts +12 -0
- package/dist/js/types/ifBinding.d.ts.map +1 -0
- package/dist/js/types/index.d.ts +10 -0
- package/dist/js/types/index.d.ts.map +1 -0
- package/dist/js/types/modelBinding.d.ts +12 -0
- package/dist/js/types/modelBinding.d.ts.map +1 -0
- package/dist/js/types/postProcess.d.ts +3 -0
- package/dist/js/types/postProcess.d.ts.map +1 -0
- package/dist/js/types/pubSub.d.ts +11 -0
- package/dist/js/types/pubSub.d.ts.map +1 -0
- package/dist/js/types/reactiveProxy.d.ts +28 -0
- package/dist/js/types/reactiveProxy.d.ts.map +1 -0
- package/dist/js/types/renderForOfBinding.d.ts +8 -0
- package/dist/js/types/renderForOfBinding.d.ts.map +1 -0
- package/dist/js/types/renderIfBinding.d.ts +22 -0
- package/dist/js/types/renderIfBinding.d.ts.map +1 -0
- package/dist/js/types/renderIteration.d.ts +16 -0
- package/dist/js/types/renderIteration.d.ts.map +1 -0
- package/dist/js/types/renderTemplate.d.ts +14 -0
- package/dist/js/types/renderTemplate.d.ts.map +1 -0
- package/dist/js/types/renderTemplatesBinding.d.ts +19 -0
- package/dist/js/types/renderTemplatesBinding.d.ts.map +1 -0
- package/dist/js/types/showBinding.d.ts +13 -0
- package/dist/js/types/showBinding.d.ts.map +1 -0
- package/dist/js/types/switchBinding.d.ts +13 -0
- package/dist/js/types/switchBinding.d.ts.map +1 -0
- package/dist/js/types/textBinding.d.ts +13 -0
- package/dist/js/types/textBinding.d.ts.map +1 -0
- package/dist/js/types/types.d.ts +111 -0
- package/dist/js/types/types.d.ts.map +1 -0
- package/dist/js/types/util.d.ts +119 -0
- package/dist/js/types/util.d.ts.map +1 -0
- package/dist/js/types.d.ts +111 -0
- package/dist/js/types.d.ts.map +1 -0
- package/dist/js/util.d.ts +119 -0
- package/dist/js/util.d.ts.map +1 -0
- package/eslint.config.js +124 -0
- package/examples/DBMONSTER_COMPARISON.md +123 -0
- package/examples/afterRenderDemo.html +119 -0
- package/examples/bootstrap/css/animate.css +1579 -1579
- package/examples/bootstrap/css/bootstrap.min.css +6 -6
- package/examples/bootstrap/css/homeservices.css +378 -390
- package/examples/bootstrap/css/open-iconic.css +511 -511
- package/examples/bootstrap/fonts/open-iconic.svg +543 -543
- package/examples/bootstrap/js/compMessageDialog.js +20 -19
- package/examples/bootstrap/js/compSearchBar.js +12 -19
- package/examples/bootstrap/js/compSearchResults.js +50 -46
- package/examples/bootstrap/js/featureAdsResult.json +65 -65
- package/examples/bootstrap/js/searchResult.json +57 -57
- package/examples/bootstrap.html +343 -332
- package/examples/css/baseTodo.css +141 -141
- package/examples/css/dbMonsterStyles.css +27 -27
- package/examples/css/indexTodo.css +374 -374
- package/examples/dbmonsterForOfReactive.html +40 -0
- package/examples/dbmonsterReact.html +19 -0
- package/examples/forOfBindingSimpleDebug.html +45 -0
- package/examples/form.html +20 -4
- package/examples/globalConfig.html +131 -0
- package/examples/js/afterRenderDemo.js +190 -0
- package/examples/js/appTodo.js +46 -46
- package/examples/js/attrBindingDemo.js +2 -2
- package/examples/js/dbMonApp.js +24 -26
- package/examples/js/dbMonAppReact.jsx +79 -0
- package/examples/js/dbMonAppReactive.js +28 -0
- package/examples/js/fiberDemo.js +4 -4
- package/examples/js/filtersDemo.js +8 -8
- package/examples/js/forOfDemo.js +7 -9
- package/examples/js/forOfDemoComplex.js +44 -17
- package/examples/js/form.js +44 -12
- package/examples/js/globalConfig.js +117 -0
- package/examples/js/ifBindingDemo.js +16 -16
- package/examples/js/reactiveDemo.js +119 -0
- package/examples/js/switchBindingDemo.js +8 -8
- package/examples/react-dbmonster/dist/bundle.js +43 -0
- package/examples/react-dbmonster/package-lock.json +537 -0
- package/examples/react-dbmonster/package.json +16 -0
- package/examples/react-dbmonster/src/index.jsx +80 -0
- package/examples/reactiveDemo.html +127 -0
- package/examples/refreshRateTest.html +75 -75
- package/index.html +841 -0
- package/package.json +31 -34
- package/rollup.config.js +79 -36
- package/src/{_escape.js → _escape.ts} +19 -17
- package/src/applyBinding.ts +179 -0
- package/src/{attrBinding.js → attrBinding.ts} +14 -13
- package/src/binder.ts +289 -0
- package/src/changeBinding.ts +93 -0
- package/src/{commentWrapper.js → commentWrapper.ts} +33 -30
- package/src/config.ts +107 -0
- package/src/createBindingOption.ts +91 -0
- package/src/createEventBinding.ts +88 -0
- package/src/{cssBinding.js → cssBinding.ts} +13 -11
- package/src/{domWalker.js → domWalker.ts} +44 -30
- package/src/{forOfBinding.js → forOfBinding.ts} +4 -3
- package/src/hoverBinding.ts +84 -0
- package/src/{ifBinding.js → ifBinding.ts} +14 -12
- package/src/index.ts +53 -0
- package/src/{modelBinding.js → modelBinding.ts} +11 -9
- package/src/postProcess.ts +22 -0
- package/src/{pubSub.js → pubSub.ts} +24 -15
- package/src/reactiveProxy.ts +285 -0
- package/src/{renderForOfBinding.js → renderForOfBinding.ts} +55 -33
- package/src/{renderIfBinding.js → renderIfBinding.ts} +45 -20
- package/src/renderIteration.ts +53 -0
- package/src/renderTemplate.ts +165 -0
- package/src/renderTemplatesBinding.ts +73 -0
- package/src/{showBinding.js → showBinding.ts} +4 -3
- package/src/{switchBinding.js → switchBinding.ts} +18 -15
- package/src/{textBinding.js → textBinding.ts} +5 -4
- package/src/types.ts +124 -0
- package/src/util.ts +810 -0
- package/test/css/reporter.css +9 -9
- package/test/fixtures/dataBindBootstrap.html +2 -2
- package/test/fixtures/formBindings.html +9 -1
- package/test/globals.d.ts +19 -0
- package/test/helpers/testHelper.js +46 -11
- package/test/mocks/featureAdsResult.json +65 -65
- package/test/mocks/searchResult.json +57 -57
- package/test/specs/{attrBinding.spec.js → attrBinding.spec.ts} +103 -106
- package/test/specs/{binder.spec.js → binder.spec.ts} +29 -27
- package/test/specs/blurBinding.spec.ts +60 -0
- package/test/specs/chainableUse.spec.ts +125 -0
- package/test/specs/clickBinding.spec.ts +194 -0
- package/test/specs/{cssBinding.spec.js → cssBinding.spec.ts} +72 -79
- package/test/specs/{dataBindBootstrap.spec.js → dataBindBootstrap.spec.ts} +332 -313
- package/test/specs/{filter.spec.js → filter.spec.ts} +75 -76
- package/test/specs/{forOfBinding.spec.js → forOfBinding.spec.ts} +208 -219
- package/test/specs/formBinding.spec.ts +272 -0
- package/test/specs/ifBinding.spec.ts +165 -0
- package/test/specs/{nestedComponent.spec.js → nestedComponent.spec.ts} +88 -88
- package/test/specs/reactiveProxy.spec.ts +465 -0
- package/test/specs/{showBinding.spec.js → showBinding.spec.ts} +148 -149
- package/test/specs/{switchBinding.spec.js → switchBinding.spec.ts} +172 -173
- package/test/specs/templateBinding.spec.ts +273 -0
- package/test/specs/{textBinding.spec.js → textBinding.spec.ts} +47 -48
- package/test/tsconfig.json +31 -0
- package/test-output.txt +200 -0
- package/test-reactive.html +224 -0
- package/tsconfig.json +28 -0
- package/vendors/lodash.custom.js +4577 -4577
- package/vendors/lodash.custom.min.js +45 -45
- package/vitest.config.js +27 -0
- package/.eslintrc.js +0 -1
- package/.grunt/grunt-contrib-jasmine/boot.js +0 -161
- package/.grunt/grunt-contrib-jasmine/dist/js/dataBind.js +0 -9
- package/.grunt/grunt-contrib-jasmine/grunt-template-jasmine-istanbul/reporter.js +0 -23
- package/.grunt/grunt-contrib-jasmine/jasmine-html.js +0 -853
- package/.grunt/grunt-contrib-jasmine/jasmine.css +0 -271
- package/.grunt/grunt-contrib-jasmine/jasmine.js +0 -9761
- package/.grunt/grunt-contrib-jasmine/jasmine_favicon.png +0 -0
- package/.grunt/grunt-contrib-jasmine/json2.js +0 -489
- package/.grunt/grunt-contrib-jasmine/reporter.js +0 -107
- package/coverage/coverage.json +0 -1
- package/coverage/lcov/lcov-report/base.css +0 -213
- package/coverage/lcov/lcov-report/index.html +0 -93
- package/coverage/lcov/lcov-report/js/dataBind.js.html +0 -6596
- package/coverage/lcov/lcov-report/js/index.html +0 -93
- package/coverage/lcov/lcov-report/prettify.css +0 -1
- package/coverage/lcov/lcov-report/prettify.js +0 -1
- package/coverage/lcov/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov/lcov-report/sorter.js +0 -158
- package/coverage/lcov/lcov.info +0 -1991
- package/eslintrc.json +0 -40
- package/examples/bootstrap/js/bootstrap.min.js +0 -6
- package/examples/bootstrap/js/popper.min.js +0 -5
- package/examples/bootstrap/js/searchSuggestion.js +0 -58
- package/examples/bootstrap/js/typeahead.jquery.js +0 -1538
- package/gruntfile.js +0 -92
- package/gulpfile.js +0 -32
- package/src/binder.js +0 -422
- package/src/changeBinding.js +0 -57
- package/src/config.js +0 -65
- package/src/createBindingOption.js +0 -66
- package/src/createEventBinding.js +0 -46
- package/src/eventSystem.js +0 -46
- package/src/hoverBinding.js +0 -57
- package/src/index.js +0 -26
- package/src/renderTemplate.js +0 -128
- package/src/util.js +0 -648
- package/test/specs/blurBinding.spec.js +0 -57
- package/test/specs/formBinding.spec.js +0 -292
- package/test/specs/ifBinding.spec.js +0 -169
- package/test/specs/templateBinding.spec.js +0 -117
- package/vendors/jasmine-jquery.js +0 -841
- package/vendors/jquery-3.2.1.min.js +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
(() => {
|
|
3
3
|
const myComponentViewModel = {
|
|
4
4
|
renderIntro: false,
|
|
@@ -13,36 +13,36 @@
|
|
|
13
13
|
{title: 'The Ugly Duckling', value: 's2'},
|
|
14
14
|
{title: 'The Giving Tree', value: 's3'},
|
|
15
15
|
],
|
|
16
|
-
setStoryOptionAttr
|
|
16
|
+
setStoryOptionAttr($data, oldAttrObj, $el) {
|
|
17
17
|
if ($data && $data.value) {
|
|
18
18
|
return {
|
|
19
19
|
value: $data.value,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
onSelectedStory
|
|
23
|
+
onSelectedStory(e, $el, newValue, oldValue) {
|
|
24
24
|
e.preventDefault();
|
|
25
25
|
this.APP.publish('SELECTED_STORY', newValue);
|
|
26
26
|
},
|
|
27
|
-
renderItem
|
|
27
|
+
renderItem(e, $el) {
|
|
28
28
|
e.preventDefault();
|
|
29
29
|
this.renderIntro = true;
|
|
30
|
-
|
|
30
|
+
// Reactive mode - automatic render!
|
|
31
31
|
},
|
|
32
|
-
removeItem
|
|
32
|
+
removeItem(e, $el) {
|
|
33
33
|
e.preventDefault();
|
|
34
34
|
this.renderIntro = false;
|
|
35
|
-
|
|
35
|
+
// Reactive mode - automatic render!
|
|
36
36
|
},
|
|
37
|
-
updateView(opt) {
|
|
38
|
-
|
|
37
|
+
updateView(opt) { // Note: render is automatic in reactive mode
|
|
38
|
+
// Reactive mode - automatic render!
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const compStoryDetailViewModel = {
|
|
43
43
|
selectedStory: '',
|
|
44
44
|
story: {},
|
|
45
|
-
setStoryImgAttr
|
|
45
|
+
setStoryImgAttr() {
|
|
46
46
|
const picPath = this.story.pic || '';
|
|
47
47
|
const ret = {
|
|
48
48
|
alt: this.story.title,
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
return ret;
|
|
57
57
|
},
|
|
58
|
-
onStoryChange
|
|
58
|
+
onStoryChange(id) {
|
|
59
59
|
if (storiesData[id] && id !== this.selectedStory) {
|
|
60
60
|
this.story = storiesData[id];
|
|
61
61
|
this.selectedStory = id;
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
this.story = '';
|
|
64
64
|
this.selectedStory = '';
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
// Reactive mode - automatic render!
|
|
67
67
|
},
|
|
68
|
-
updateView(opt) {
|
|
69
|
-
|
|
68
|
+
updateView(opt) { // Note: render is automatic in reactive mode
|
|
69
|
+
// Reactive mode - automatic render!
|
|
70
70
|
},
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
|
|
97
97
|
// main
|
|
98
98
|
const myComponent = dataBind.init(document.querySelector('[data-bind-comp="myComponent"]'), myComponentViewModel);
|
|
99
|
-
myComponent.render().then(
|
|
99
|
+
myComponent.render().then(() => {
|
|
100
100
|
// for debug
|
|
101
101
|
console.log(myComponent);
|
|
102
102
|
window.myComponent = myComponent;
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
|
|
105
105
|
// story detail componenet
|
|
106
106
|
const compStoryDetail = dataBind.init(document.querySelector('[data-bind-comp="compStoryDetail"]'), compStoryDetailViewModel);
|
|
107
|
-
compStoryDetail.render().then(
|
|
107
|
+
compStoryDetail.render().then((thisComponent) => {
|
|
108
108
|
thisComponent.subscribe('SELECTED_STORY', thisComponent.viewModel.onStoryChange);
|
|
109
109
|
// for debug
|
|
110
110
|
console.log(compStoryDetail);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Manual Mode Component
|
|
2
|
+
(() => {
|
|
3
|
+
const viewModel = {
|
|
4
|
+
name: 'John Doe',
|
|
5
|
+
age: 30,
|
|
6
|
+
counter: 0,
|
|
7
|
+
|
|
8
|
+
// Click handler methods
|
|
9
|
+
updateData() {
|
|
10
|
+
this.name = 'Jane Smith';
|
|
11
|
+
this.age = 25;
|
|
12
|
+
// MUST call render manually in manual mode
|
|
13
|
+
this.APP.render();
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
incrementCounter() {
|
|
17
|
+
this.counter += 1;
|
|
18
|
+
// MUST call render manually in manual mode
|
|
19
|
+
this.APP.render();
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const component = dataBind.init(
|
|
24
|
+
document.querySelector('[data-bind-comp="manual-component"]'),
|
|
25
|
+
viewModel,
|
|
26
|
+
{reactive: false}, // Explicitly disable reactive mode for manual mode
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
component.render().then(() => {
|
|
30
|
+
console.log('Manual component ready');
|
|
31
|
+
window.manualComponent = component;
|
|
32
|
+
});
|
|
33
|
+
})();
|
|
34
|
+
|
|
35
|
+
// Reactive Mode Component
|
|
36
|
+
(() => {
|
|
37
|
+
const viewModel = {
|
|
38
|
+
name: 'John Doe',
|
|
39
|
+
age: 30,
|
|
40
|
+
counter: 0,
|
|
41
|
+
|
|
42
|
+
// Click handler methods - NO render() calls needed!
|
|
43
|
+
updateData() {
|
|
44
|
+
this.name = 'Jane Smith';
|
|
45
|
+
this.age = 25;
|
|
46
|
+
// Automatic render in reactive mode!
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
incrementCounter() {
|
|
50
|
+
this.counter += 1;
|
|
51
|
+
// Automatic render in reactive mode!
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const component = dataBind.init(
|
|
56
|
+
document.querySelector('[data-bind-comp="reactive-component"]'),
|
|
57
|
+
viewModel,
|
|
58
|
+
// Reactive mode is now the default! No options needed.
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
component.render().then(() => {
|
|
62
|
+
console.log('Reactive component ready');
|
|
63
|
+
console.log('isReactive:', component.isReactive);
|
|
64
|
+
window.reactiveComponent = component;
|
|
65
|
+
});
|
|
66
|
+
})();
|
|
67
|
+
|
|
68
|
+
// Advanced Reactive Demo with Arrays
|
|
69
|
+
(() => {
|
|
70
|
+
const viewModel = {
|
|
71
|
+
todos: [
|
|
72
|
+
{text: 'Learn dataBind.js', completed: false},
|
|
73
|
+
{text: 'Build awesome app', completed: false},
|
|
74
|
+
{text: 'Ship to production', completed: false},
|
|
75
|
+
],
|
|
76
|
+
todoCounter: 4,
|
|
77
|
+
|
|
78
|
+
// Click handler methods - all automatic!
|
|
79
|
+
addTodo() {
|
|
80
|
+
this.todos.push({
|
|
81
|
+
text: `New todo ${this.todoCounter}`,
|
|
82
|
+
completed: false,
|
|
83
|
+
});
|
|
84
|
+
this.todoCounter += 1;
|
|
85
|
+
// Automatic render!
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
completeFirst() {
|
|
89
|
+
if (this.todos.length > 0) {
|
|
90
|
+
this.todos[0].completed = true;
|
|
91
|
+
// Automatic render!
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
removeLast() {
|
|
96
|
+
this.todos.pop();
|
|
97
|
+
// Automatic render!
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
batchUpdate() {
|
|
101
|
+
// Multiple changes batched into single render automatically!
|
|
102
|
+
this.todos.push({text: 'Batch todo 1', completed: false});
|
|
103
|
+
this.todos.push({text: 'Batch todo 2', completed: false});
|
|
104
|
+
this.todos.push({text: 'Batch todo 3', completed: false});
|
|
105
|
+
// Only 1 render happens due to requestAnimationFrame debouncing!
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const component = dataBind.init(
|
|
110
|
+
document.querySelector('[data-bind-comp="advanced-reactive"]'),
|
|
111
|
+
viewModel,
|
|
112
|
+
// Reactive mode is the default!
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
component.render().then(() => {
|
|
116
|
+
console.log('Advanced reactive component ready');
|
|
117
|
+
window.advancedReactiveComponent = component;
|
|
118
|
+
});
|
|
119
|
+
})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
(() => {
|
|
3
3
|
const myComponentViewModel = {
|
|
4
4
|
heading: 'This heading is inside switch binding',
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
{title: 'The Ugly Duckling', value: 's2'},
|
|
12
12
|
{title: 'The Giving Tree', value: 's3'},
|
|
13
13
|
],
|
|
14
|
-
setStoryOptionAttr
|
|
14
|
+
setStoryOptionAttr($data, oldAttrObj, $el) {
|
|
15
15
|
if ($data && $data.value) {
|
|
16
16
|
return {
|
|
17
17
|
value: $data.value,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
onSelectedStory
|
|
21
|
+
onSelectedStory(e, $el, newValue, oldValue) {
|
|
22
22
|
const id = newValue;
|
|
23
23
|
|
|
24
24
|
e.preventDefault();
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
this.story = {};
|
|
31
31
|
this.selectedStory = '';
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
// Reactive mode - automatic render!
|
|
34
34
|
},
|
|
35
|
-
setStoryImgAttr
|
|
35
|
+
setStoryImgAttr() {
|
|
36
36
|
const picPath = this.story.pic || '';
|
|
37
37
|
const ret = {
|
|
38
38
|
alt: this.story.title,
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
}
|
|
46
46
|
return ret;
|
|
47
47
|
},
|
|
48
|
-
updateView(opt) {
|
|
49
|
-
|
|
48
|
+
updateView(opt) { // Note: render is automatic in reactive mode
|
|
49
|
+
// Reactive mode - automatic render!
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
52
|
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
// start binding on DOM ready
|
|
76
76
|
// main
|
|
77
77
|
const myComponent = dataBind.init(document.querySelector('[data-bind-comp="myComponent"]'), myComponentViewModel);
|
|
78
|
-
myComponent.render().then(
|
|
78
|
+
myComponent.render().then(() => {
|
|
79
79
|
// for debug
|
|
80
80
|
console.log(myComponent);
|
|
81
81
|
window.myComponent = myComponent;
|