@gogocat/data-bind 1.12.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 +2756 -2530
- 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/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 +14 -14
- 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.js → applyBinding.ts} +27 -18
- package/src/{attrBinding.js → attrBinding.ts} +14 -13
- package/src/{binder.js → binder.ts} +289 -181
- package/src/changeBinding.ts +93 -0
- package/src/{commentWrapper.js → commentWrapper.ts} +33 -30
- package/src/config.ts +107 -0
- package/src/{createBindingOption.js → createBindingOption.ts} +39 -15
- 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.js → postProcess.ts} +6 -4
- package/src/{pubSub.js → pubSub.ts} +24 -21
- package/src/reactiveProxy.ts +285 -0
- package/src/{renderForOfBinding.js → renderForOfBinding.ts} +54 -32
- package/src/{renderIfBinding.js → renderIfBinding.ts} +41 -19
- package/src/{renderIteration.js → renderIteration.ts} +24 -8
- 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/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/applyBindingExport.js +0 -5
- package/src/changeBinding.js +0 -63
- package/src/config.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/renderTemplatesBinding.js +0 -44
- package/src/util.js +0 -648
- package/test/specs/blurBinding.spec.js +0 -57
- package/test/specs/formBinding.spec.js +0 -316
- 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
package/.editorconfig
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# EditorConfig is awesome: https://EditorConfig.org
|
|
2
|
-
|
|
3
|
-
# top-most EditorConfig file
|
|
4
|
-
root = true
|
|
5
|
-
|
|
6
|
-
# Unix-style newlines with a newline ending every file
|
|
7
|
-
[*]
|
|
8
|
-
end_of_line = crlf
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
indent_style = space
|
|
11
|
-
indent_size = 4
|
|
12
|
-
max_line_length = 150
|
|
13
|
-
tab_width = 4
|
|
14
|
-
trim_trailing_whitespace = true
|
|
1
|
+
# EditorConfig is awesome: https://EditorConfig.org
|
|
2
|
+
|
|
3
|
+
# top-most EditorConfig file
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
# Unix-style newlines with a newline ending every file
|
|
7
|
+
[*]
|
|
8
|
+
end_of_line = crlf
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
indent_style = space
|
|
11
|
+
indent_size = 4
|
|
12
|
+
max_line_length = 150
|
|
13
|
+
tab_width = 4
|
|
14
|
+
trim_trailing_whitespace = true
|
package/.vscode/launch.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.2.0",
|
|
3
|
-
"configurations": [{
|
|
4
|
-
"type": "node",
|
|
5
|
-
"request": "launch",
|
|
6
|
-
"name": "Gulp task",
|
|
7
|
-
"program": "${workspaceRoot}/integrationtests/node_modules/gulp/bin/gulp.js",
|
|
8
|
-
"args": [
|
|
9
|
-
"test:e2e"
|
|
10
|
-
],
|
|
11
|
-
"cwd": "${workspaceRoot}/integrationtests"
|
|
12
|
-
}]
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [{
|
|
4
|
+
"type": "node",
|
|
5
|
+
"request": "launch",
|
|
6
|
+
"name": "Gulp task",
|
|
7
|
+
"program": "${workspaceRoot}/integrationtests/node_modules/gulp/bin/gulp.js",
|
|
8
|
+
"args": [
|
|
9
|
+
"test:e2e"
|
|
10
|
+
],
|
|
11
|
+
"cwd": "${workspaceRoot}/integrationtests"
|
|
12
|
+
}]
|
|
13
13
|
}
|
package/CONFIGURATION.md
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# dataBind.js Configuration Guide
|
|
2
|
+
|
|
3
|
+
This guide explains how to configure dataBind.js globally and per-instance.
|
|
4
|
+
|
|
5
|
+
## Global Configuration with `use()`
|
|
6
|
+
|
|
7
|
+
The `use()` function allows you to set global defaults that apply to all components created with `init()`. The `use()` function is **chainable**, allowing you to call `init()` directly after it.
|
|
8
|
+
|
|
9
|
+
### Setting Global Reactive Mode
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// Traditional style: separate calls
|
|
13
|
+
dataBind.use({ reactive: false });
|
|
14
|
+
const app = dataBind.init(rootElement, viewModel);
|
|
15
|
+
// This component is in manual mode
|
|
16
|
+
|
|
17
|
+
// Chainable style: one line
|
|
18
|
+
const app = dataBind.use({ reactive: false }).init(rootElement, viewModel);
|
|
19
|
+
// This component is in manual mode
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Setting Global Track Changes
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
// Enable change tracking globally
|
|
26
|
+
dataBind.use({
|
|
27
|
+
reactive: true,
|
|
28
|
+
trackChanges: true
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// All components will now have reactive mode with change tracking
|
|
32
|
+
const app = dataBind.init(rootElement, viewModel);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Custom Binding Attributes
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
// Use custom data attributes for bindings
|
|
39
|
+
dataBind.use({
|
|
40
|
+
bindingAttrs: {
|
|
41
|
+
text: 'data-my-text',
|
|
42
|
+
click: 'data-my-click',
|
|
43
|
+
// ... other custom attributes
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Combined Configuration
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
dataBind.use({
|
|
52
|
+
reactive: true,
|
|
53
|
+
trackChanges: false,
|
|
54
|
+
bindingAttrs: {
|
|
55
|
+
// Custom attributes
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Per-Instance Options
|
|
61
|
+
|
|
62
|
+
Instance-specific options passed to `init()` will **override** global defaults.
|
|
63
|
+
|
|
64
|
+
### Override Global Reactive Setting
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
// Global default is reactive: true
|
|
68
|
+
dataBind.use({ reactive: true });
|
|
69
|
+
|
|
70
|
+
// But this specific component uses manual mode
|
|
71
|
+
const manualApp = dataBind.init(rootElement, viewModel, {
|
|
72
|
+
reactive: false
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// This component uses reactive mode (global default)
|
|
76
|
+
const reactiveApp = dataBind.init(rootElement2, viewModel2);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Per-Instance Track Changes
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
dataBind.use({ reactive: true });
|
|
83
|
+
|
|
84
|
+
// Enable change tracking for this component only
|
|
85
|
+
const app = dataBind.init(rootElement, viewModel, {
|
|
86
|
+
trackChanges: true
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Default Configuration
|
|
91
|
+
|
|
92
|
+
By default (without calling `use()`), dataBind.js uses:
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
{
|
|
96
|
+
reactive: true, // Reactive mode enabled
|
|
97
|
+
trackChanges: false
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Configuration Precedence
|
|
102
|
+
|
|
103
|
+
The configuration follows this precedence (highest to lowest):
|
|
104
|
+
|
|
105
|
+
1. **Instance options** - Options passed to `init()`
|
|
106
|
+
2. **Global defaults** - Options set via `use()`
|
|
107
|
+
3. **Built-in defaults** - `{ reactive: true }`
|
|
108
|
+
|
|
109
|
+
### Example
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
// Step 1: Built-in default
|
|
113
|
+
// reactive: true (built-in)
|
|
114
|
+
|
|
115
|
+
// Step 2: Set global default
|
|
116
|
+
dataBind.use({ reactive: false });
|
|
117
|
+
// reactive: false (global override)
|
|
118
|
+
|
|
119
|
+
// Step 3: Create components
|
|
120
|
+
const app1 = dataBind.init(el1, vm1);
|
|
121
|
+
// reactive: false (uses global default)
|
|
122
|
+
|
|
123
|
+
const app2 = dataBind.init(el2, vm2, { reactive: true });
|
|
124
|
+
// reactive: true (instance override)
|
|
125
|
+
|
|
126
|
+
const app3 = dataBind.init(el3, vm3, {});
|
|
127
|
+
// reactive: false (uses global default)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Use Cases
|
|
131
|
+
|
|
132
|
+
### Scenario 1: Default Reactive Mode (Recommended)
|
|
133
|
+
|
|
134
|
+
Most applications should use reactive mode for better developer experience:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// No configuration needed - reactive mode is default
|
|
138
|
+
const app = dataBind.init(document.getElementById('app'), viewModel);
|
|
139
|
+
|
|
140
|
+
// Update data - automatic rendering
|
|
141
|
+
app.viewModel.name = 'Jane';
|
|
142
|
+
app.viewModel.items.push(newItem);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Scenario 2: Opt-in Manual Mode for Performance
|
|
146
|
+
|
|
147
|
+
For performance-critical applications (like benchmarks):
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
const app = dataBind.init(document.getElementById('app'), viewModel, {
|
|
151
|
+
reactive: false
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Update data manually
|
|
155
|
+
viewModel.name = 'Jane';
|
|
156
|
+
app.render(); // Manual render call
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Scenario 3: Mixed Mode Application
|
|
160
|
+
|
|
161
|
+
Some components reactive, others manual:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
// Set global default to reactive
|
|
165
|
+
dataBind.use({ reactive: true });
|
|
166
|
+
|
|
167
|
+
// Most components use reactive mode
|
|
168
|
+
const mainApp = dataBind.init(document.getElementById('main'), mainVM);
|
|
169
|
+
|
|
170
|
+
// Performance-critical component uses manual mode
|
|
171
|
+
const perfApp = dataBind.init(
|
|
172
|
+
document.getElementById('perf'),
|
|
173
|
+
perfVM,
|
|
174
|
+
{ reactive: false }
|
|
175
|
+
);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Scenario 4: Disable Reactive Globally (Legacy Mode)
|
|
179
|
+
|
|
180
|
+
For backward compatibility with existing codebases:
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
// Disable reactive mode for all components
|
|
184
|
+
dataBind.use({ reactive: false });
|
|
185
|
+
|
|
186
|
+
// All components now use manual mode by default
|
|
187
|
+
const app1 = dataBind.init(el1, vm1);
|
|
188
|
+
const app2 = dataBind.init(el2, vm2);
|
|
189
|
+
|
|
190
|
+
// Both require manual render() calls
|
|
191
|
+
app1.render();
|
|
192
|
+
app2.render();
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Migration Guide
|
|
196
|
+
|
|
197
|
+
### From Manual to Reactive Mode
|
|
198
|
+
|
|
199
|
+
**Before (Manual Mode):**
|
|
200
|
+
```javascript
|
|
201
|
+
const app = dataBind.init(rootElement, viewModel);
|
|
202
|
+
|
|
203
|
+
function updateData() {
|
|
204
|
+
viewModel.name = 'New Name';
|
|
205
|
+
viewModel.items.push(newItem);
|
|
206
|
+
app.render(); // Manual render
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**After (Reactive Mode):**
|
|
211
|
+
```javascript
|
|
212
|
+
const app = dataBind.init(rootElement, viewModel);
|
|
213
|
+
// Reactive mode is default
|
|
214
|
+
|
|
215
|
+
function updateData() {
|
|
216
|
+
// IMPORTANT: Use component.viewModel for reactive updates
|
|
217
|
+
app.viewModel.name = 'New Name';
|
|
218
|
+
app.viewModel.items.push(newItem);
|
|
219
|
+
// Automatic render!
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Common Migration Issues
|
|
224
|
+
|
|
225
|
+
**Issue**: Updates don't trigger renders
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
// ❌ Wrong - updating original viewModel
|
|
229
|
+
viewModel.name = 'Jane';
|
|
230
|
+
|
|
231
|
+
// ✅ Correct - updating reactive proxy
|
|
232
|
+
app.viewModel.name = 'Jane';
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Issue**: Need manual render control
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
// Use manual mode for specific components
|
|
239
|
+
const app = dataBind.init(rootElement, viewModel, {
|
|
240
|
+
reactive: false
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Best Practices
|
|
245
|
+
|
|
246
|
+
1. **Use reactive mode by default** - Better DX, less boilerplate
|
|
247
|
+
2. **Set global config early** - Call `use()` before creating any components
|
|
248
|
+
3. **Use manual mode for benchmarks** - Precise control for performance testing
|
|
249
|
+
4. **Update via component.viewModel** - Always use the reactive proxy in reactive mode
|
|
250
|
+
5. **Document mode in complex apps** - Make it clear which components are reactive/manual
|
|
251
|
+
|
|
252
|
+
## API Reference
|
|
253
|
+
|
|
254
|
+
### `dataBind.use(settings)`
|
|
255
|
+
|
|
256
|
+
Set global configuration for all components.
|
|
257
|
+
|
|
258
|
+
**Parameters:**
|
|
259
|
+
- `settings` (Object)
|
|
260
|
+
- `reactive` (Boolean) - Enable/disable reactive mode globally
|
|
261
|
+
- `trackChanges` (Boolean) - Enable/disable change tracking globally
|
|
262
|
+
- `bindingAttrs` (Object) - Custom binding attribute names
|
|
263
|
+
|
|
264
|
+
**Returns:** void
|
|
265
|
+
|
|
266
|
+
**Example:**
|
|
267
|
+
```javascript
|
|
268
|
+
dataBind.use({
|
|
269
|
+
reactive: true,
|
|
270
|
+
trackChanges: false
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### `dataBind.init(element, viewModel, options)`
|
|
275
|
+
|
|
276
|
+
Create a new component instance.
|
|
277
|
+
|
|
278
|
+
**Parameters:**
|
|
279
|
+
- `element` (HTMLElement) - Root element for the component
|
|
280
|
+
- `viewModel` (Object) - Data model for the component
|
|
281
|
+
- `options` (Object, optional)
|
|
282
|
+
- `reactive` (Boolean) - Override global reactive setting
|
|
283
|
+
- `trackChanges` (Boolean) - Override global trackChanges setting
|
|
284
|
+
|
|
285
|
+
**Returns:** Binder instance
|
|
286
|
+
|
|
287
|
+
**Example:**
|
|
288
|
+
```javascript
|
|
289
|
+
const app = dataBind.init(
|
|
290
|
+
document.getElementById('app'),
|
|
291
|
+
{ name: 'John', age: 30 },
|
|
292
|
+
{ reactive: false }
|
|
293
|
+
);
|
|
294
|
+
```
|