@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/gruntfile.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module.exports = function(grunt) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// Project configuration.
|
|
5
|
-
grunt.initConfig({
|
|
6
|
-
pkg: grunt.file.readJSON('package.json'),
|
|
7
|
-
|
|
8
|
-
// create a static server for jasmine / PhantomJS
|
|
9
|
-
connect: {
|
|
10
|
-
test: {
|
|
11
|
-
options: {
|
|
12
|
-
hostname: 'localhost',
|
|
13
|
-
port: 8887,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
debug: {
|
|
17
|
-
options: {
|
|
18
|
-
hostname: 'localhost',
|
|
19
|
-
port: 8889,
|
|
20
|
-
keepalive: true,
|
|
21
|
-
open: 'http://localhost:8889/_SpecRunner.html',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
// this is just config for jasmine - not a grunt module
|
|
27
|
-
jasmineTestSettings: {
|
|
28
|
-
src: ['./dist/js/dataBind.min.js'],
|
|
29
|
-
host: 'http://localhost:8887',
|
|
30
|
-
specs: './test/specs/*.spec.js',
|
|
31
|
-
styles: './test/css/reporter.css',
|
|
32
|
-
vendor: ['./vendors/jquery-3.2.1.min.js', './vendors/jasmine-jquery.js'],
|
|
33
|
-
helpers: ['./test/helpers/testHelper.js'],
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
jasmine: {
|
|
37
|
-
test: {
|
|
38
|
-
src: '<%= jasmineTestSettings.src %>',
|
|
39
|
-
options: {
|
|
40
|
-
'styles': '<%= jasmineTestSettings.styles %>',
|
|
41
|
-
'host': '<%= jasmineTestSettings.host %>',
|
|
42
|
-
'specs': '<%= jasmineTestSettings.specs %>',
|
|
43
|
-
'vendor': '<%= jasmineTestSettings.vendor %>',
|
|
44
|
-
'helpers': '<%= jasmineTestSettings.helpers %>',
|
|
45
|
-
'keepRunner': true,
|
|
46
|
-
'--web-security': 'no',
|
|
47
|
-
'--local-to-remote-url-access': true,
|
|
48
|
-
'--ignore-ssl-errors': true,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
// code test coverage
|
|
52
|
-
coverage: {
|
|
53
|
-
src: '<%= jasmineTestSettings.src %>',
|
|
54
|
-
options: {
|
|
55
|
-
'host': '<%= jasmineTestSettings.host %>',
|
|
56
|
-
'specs': '<%= jasmineTestSettings.specs %>',
|
|
57
|
-
'vendor': '<%= jasmineTestSettings.vendor %>',
|
|
58
|
-
'helpers': '<%= jasmineTestSettings.helpers %>',
|
|
59
|
-
'keepRunner': true,
|
|
60
|
-
'--web-security': 'no',
|
|
61
|
-
'--local-to-remote-url-access': true,
|
|
62
|
-
'--ignore-ssl-errors': true,
|
|
63
|
-
|
|
64
|
-
'template': require('grunt-template-jasmine-istanbul'),
|
|
65
|
-
'templateOptions': {
|
|
66
|
-
coverage: './coverage/coverage.json',
|
|
67
|
-
report: [
|
|
68
|
-
{
|
|
69
|
-
type: 'text-summary',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
type: 'lcov',
|
|
73
|
-
options: {
|
|
74
|
-
dir: './coverage/lcov',
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
grunt.loadNpmTasks('grunt-contrib-connect');
|
|
85
|
-
grunt.loadNpmTasks('grunt-contrib-jasmine');
|
|
86
|
-
grunt.loadNpmTasks('grunt-open');
|
|
87
|
-
|
|
88
|
-
// jasmine test via PhantomJS with 'connect' local server - for local dev and debug
|
|
89
|
-
grunt.registerTask('test', ['connect:test', 'jasmine:test', 'connect:debug']);
|
|
90
|
-
// jasmine test with coverage - this if for build server
|
|
91
|
-
grunt.registerTask('test:coverage', ['connect:test', 'jasmine:coverage']);
|
|
92
|
-
};
|
package/gulpfile.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const gulp = require('gulp');
|
|
2
|
-
const sourcemaps = require('gulp-sourcemaps');
|
|
3
|
-
const uglify = require('gulp-uglify-es').default;
|
|
4
|
-
const rename = require('gulp-rename');
|
|
5
|
-
const replace = require('gulp-replace');
|
|
6
|
-
|
|
7
|
-
const pkg = require('./package.json');
|
|
8
|
-
const verionToken = '@version@';
|
|
9
|
-
|
|
10
|
-
const distJsPath = './dist/js/';
|
|
11
|
-
const bundledFile = 'dataBind.js';
|
|
12
|
-
|
|
13
|
-
// set release version to source
|
|
14
|
-
gulp.task('versioning', function(cb) {
|
|
15
|
-
return gulp
|
|
16
|
-
.src(`${distJsPath}${bundledFile}`)
|
|
17
|
-
.pipe(replace(verionToken, `${pkg.version}`))
|
|
18
|
-
.pipe(gulp.dest(distJsPath));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// uglify
|
|
22
|
-
gulp.task('compress', function(cb) {
|
|
23
|
-
return gulp
|
|
24
|
-
.src(`${distJsPath}${bundledFile}`)
|
|
25
|
-
.pipe(rename({extname: '.min.js'}))
|
|
26
|
-
.pipe(sourcemaps.init())
|
|
27
|
-
.pipe(uglify())
|
|
28
|
-
.pipe(sourcemaps.write(''))
|
|
29
|
-
.pipe(gulp.dest(distJsPath));
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
gulp.task('default', gulp.series('versioning', 'compress'));
|
package/src/changeBinding.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-invalid-this */
|
|
2
|
-
import {
|
|
3
|
-
getViewModelValue,
|
|
4
|
-
setViewModelValue,
|
|
5
|
-
resolveViewModelContext,
|
|
6
|
-
resolveParamList,
|
|
7
|
-
} from './util';
|
|
8
|
-
import _escape from './_escape';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* changeBinding
|
|
12
|
-
* @description input element on change event binding. DOM -> viewModel update
|
|
13
|
-
* @param {object} cache
|
|
14
|
-
* @param {object} viewModel
|
|
15
|
-
* @param {object} bindingAttrs
|
|
16
|
-
* @param {boolean} forceRender
|
|
17
|
-
*/
|
|
18
|
-
const changeBinding = ({
|
|
19
|
-
cache,
|
|
20
|
-
viewModel,
|
|
21
|
-
bindingAttrs,
|
|
22
|
-
forceRender,
|
|
23
|
-
type = 'change',
|
|
24
|
-
}) => {
|
|
25
|
-
const handlerName = cache.dataKey;
|
|
26
|
-
let paramList = cache.parameters;
|
|
27
|
-
const modelDataKey = cache.el.getAttribute(bindingAttrs.model);
|
|
28
|
-
let newValue = '';
|
|
29
|
-
let oldValue = '';
|
|
30
|
-
let viewModelContext;
|
|
31
|
-
const APP = viewModel.APP || viewModel.$root.APP;
|
|
32
|
-
|
|
33
|
-
if (!handlerName || (!forceRender && !APP.$rootElement.contains(cache.el))) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const handlerFn = getViewModelValue(viewModel, handlerName);
|
|
38
|
-
|
|
39
|
-
if (typeof handlerFn === 'function') {
|
|
40
|
-
viewModelContext = resolveViewModelContext(viewModel, handlerName);
|
|
41
|
-
paramList = paramList ? resolveParamList(viewModel, paramList) : [];
|
|
42
|
-
|
|
43
|
-
function changeHandler(e) {
|
|
44
|
-
const $this = this;
|
|
45
|
-
const isCheckbox = $this.type === 'checkbox';
|
|
46
|
-
newValue = isCheckbox ? $this.checked : _escape($this.value);
|
|
47
|
-
// set data to viewModel
|
|
48
|
-
if (modelDataKey) {
|
|
49
|
-
oldValue = getViewModelValue(viewModel, modelDataKey);
|
|
50
|
-
setViewModelValue(viewModel, modelDataKey, newValue);
|
|
51
|
-
}
|
|
52
|
-
const args = [e, e.currentTarget, newValue, oldValue].concat(paramList);
|
|
53
|
-
handlerFn.apply(viewModelContext, args);
|
|
54
|
-
oldValue = newValue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// assing on change event
|
|
58
|
-
cache.el.removeEventListener(type, changeHandler, false);
|
|
59
|
-
cache.el.addEventListener(type, changeHandler, false);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default changeBinding;
|
package/src/config.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const bindingAttrs = {
|
|
2
|
-
comp: 'data-bind-comp',
|
|
3
|
-
tmp: 'data-bind-tmp',
|
|
4
|
-
text: 'data-bind-text',
|
|
5
|
-
click: 'data-bind-click',
|
|
6
|
-
dblclick: 'data-bind-dblclick',
|
|
7
|
-
blur: 'data-bind-blur',
|
|
8
|
-
focus: 'data-bind-focus',
|
|
9
|
-
hover: 'data-bind-hover',
|
|
10
|
-
input: 'data-bind-input',
|
|
11
|
-
change: 'data-bind-change',
|
|
12
|
-
submit: 'data-bind-submit',
|
|
13
|
-
model: 'data-bind-model',
|
|
14
|
-
show: 'data-bind-show',
|
|
15
|
-
css: 'data-bind-css',
|
|
16
|
-
attr: 'data-bind-attr',
|
|
17
|
-
forOf: 'data-bind-for',
|
|
18
|
-
if: 'data-bind-if',
|
|
19
|
-
switch: 'data-bind-switch',
|
|
20
|
-
case: 'data-bind-case',
|
|
21
|
-
default: 'data-bind-default',
|
|
22
|
-
};
|
|
23
|
-
const serverRenderedAttr = 'data-server-rendered';
|
|
24
|
-
const dataIndexAttr = 'data-index';
|
|
25
|
-
const commentPrefix = {
|
|
26
|
-
forOf: 'data-forOf_',
|
|
27
|
-
if: 'data-if_',
|
|
28
|
-
case: 'data-case_',
|
|
29
|
-
default: 'data-default_',
|
|
30
|
-
};
|
|
31
|
-
const commentSuffix = '_end';
|
|
32
|
-
|
|
33
|
-
const bindingDataReference = {
|
|
34
|
-
rootDataKey: '$root',
|
|
35
|
-
currentData: '$data',
|
|
36
|
-
currentIndex: '$index',
|
|
37
|
-
mouseEnterHandlerName: 'in',
|
|
38
|
-
mouseLeaveHandlerName: 'out',
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const bindingUpdateConditions = {
|
|
42
|
-
serverRendered: 'SERVER-RENDERED',
|
|
43
|
-
init: 'INIT',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// maximum string length before running regex
|
|
47
|
-
const maxDatakeyLength = 250;
|
|
48
|
-
|
|
49
|
-
const constants = {
|
|
50
|
-
filters: {
|
|
51
|
-
ONCE: 'once',
|
|
52
|
-
},
|
|
53
|
-
PARENT_REF: '_parent',
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
bindingAttrs,
|
|
58
|
-
dataIndexAttr,
|
|
59
|
-
serverRenderedAttr,
|
|
60
|
-
commentPrefix,
|
|
61
|
-
commentSuffix,
|
|
62
|
-
bindingUpdateConditions,
|
|
63
|
-
bindingDataReference,
|
|
64
|
-
maxDatakeyLength,
|
|
65
|
-
constants,
|
|
66
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getFormData,
|
|
3
|
-
getViewModelValue,
|
|
4
|
-
resolveViewModelContext,
|
|
5
|
-
resolveParamList,
|
|
6
|
-
} from './util';
|
|
7
|
-
|
|
8
|
-
const createEventBinding = ({
|
|
9
|
-
cache = {},
|
|
10
|
-
forceRender = false,
|
|
11
|
-
type = '',
|
|
12
|
-
viewModel = {},
|
|
13
|
-
}) => {
|
|
14
|
-
const handlerName = cache.dataKey;
|
|
15
|
-
let paramList = cache.parameters;
|
|
16
|
-
let viewModelContext;
|
|
17
|
-
const APP = viewModel.APP || viewModel.$root.APP;
|
|
18
|
-
|
|
19
|
-
if (!type || !handlerName || (!forceRender && !APP.$rootElement.contains(cache.el))) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const handlerFn = getViewModelValue(viewModel, handlerName);
|
|
24
|
-
|
|
25
|
-
if (typeof handlerFn === 'function') {
|
|
26
|
-
viewModelContext = resolveViewModelContext(viewModel, handlerName);
|
|
27
|
-
paramList = paramList ? resolveParamList(viewModel, paramList) : [];
|
|
28
|
-
|
|
29
|
-
const handlerWrap = (e) => {
|
|
30
|
-
let formData;
|
|
31
|
-
let args = [];
|
|
32
|
-
if (type === 'submit') {
|
|
33
|
-
formData = getFormData(e.currentTarget);
|
|
34
|
-
args = [e, e.currentTarget, formData].concat(paramList);
|
|
35
|
-
} else {
|
|
36
|
-
args = [e, e.currentTarget].concat(paramList);
|
|
37
|
-
}
|
|
38
|
-
handlerFn.apply(viewModelContext, args);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
cache.el.removeEventListener(type, handlerWrap, false);
|
|
42
|
-
cache.el.addEventListener(type, handlerWrap, false);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export default createEventBinding;
|
package/src/eventSystem.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// https://yiochen.github.io/blog/post/weakmap-event-system/
|
|
2
|
-
// usage:
|
|
3
|
-
// attach listener to button
|
|
4
|
-
// eventSystem.on(button, 'click', clickHandler);
|
|
5
|
-
// eventSystem.trigger(button, 'click');
|
|
6
|
-
|
|
7
|
-
const eventSystem = {
|
|
8
|
-
wm: new WeakMap(),
|
|
9
|
-
on(target, event, listener) {
|
|
10
|
-
let listeners = this.wm.get(target);
|
|
11
|
-
if (listeners === undefined) {
|
|
12
|
-
listeners = {};
|
|
13
|
-
}
|
|
14
|
-
let listenersForEvent = listeners[event];
|
|
15
|
-
if (listenersForEvent === undefined) {
|
|
16
|
-
listenersForEvent = new Set();
|
|
17
|
-
}
|
|
18
|
-
listenersForEvent.add(listener);
|
|
19
|
-
listeners[event] = listenersForEvent;
|
|
20
|
-
this.wm.add(target, listeners);
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
off(target, event, listener) {
|
|
24
|
-
const listeners = this.wm.get(target);
|
|
25
|
-
if (!listeners) return;
|
|
26
|
-
const listenersForEvent = listeners[event];
|
|
27
|
-
if (!listenersForEvent) return;
|
|
28
|
-
listenersForEvent.delete(handler);
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
trigger(target, event) {
|
|
32
|
-
const listeners = this.wm.get(target);
|
|
33
|
-
if (!listeners) return;
|
|
34
|
-
const listenersForEvent = listeners[event];
|
|
35
|
-
if (!listenersForEvent) return;
|
|
36
|
-
// TODO: check what is listenersForEvent
|
|
37
|
-
// handlers should be listeners or listenersForEvent
|
|
38
|
-
for (const handler of handlers) {
|
|
39
|
-
// we use a setTimeout here because we want event triggering to be asynchronous.
|
|
40
|
-
// setTimeout(handler, 0, event, target);
|
|
41
|
-
handler(event, target);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export default eventSystem;
|
package/src/hoverBinding.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-invalid-this */
|
|
2
|
-
import {bindingDataReference} from './config';
|
|
3
|
-
import {
|
|
4
|
-
getViewModelValue,
|
|
5
|
-
resolveViewModelContext,
|
|
6
|
-
resolveParamList,
|
|
7
|
-
} from './util';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* blurBinding
|
|
11
|
-
* DOM decleartive on blur event binding
|
|
12
|
-
* event handler bind to viewModel method according to the DOM attribute
|
|
13
|
-
* @param {object} cache
|
|
14
|
-
* @param {object} viewModel
|
|
15
|
-
* @param {object} bindingAttrs
|
|
16
|
-
* @param {boolean} forceRender
|
|
17
|
-
*/
|
|
18
|
-
const hoverBinding = (cache, viewModel, bindingAttrs, forceRender) => {
|
|
19
|
-
const handlerName = cache.dataKey;
|
|
20
|
-
let paramList = cache.parameters;
|
|
21
|
-
const inHandlerName = bindingDataReference.mouseEnterHandlerName;
|
|
22
|
-
const outHandlerName = bindingDataReference.mouseLeaveHandlerName;
|
|
23
|
-
let viewModelContext;
|
|
24
|
-
const APP = viewModel.APP || viewModel.$root.APP;
|
|
25
|
-
|
|
26
|
-
cache.elementData = cache.elementData || {};
|
|
27
|
-
|
|
28
|
-
// TODO: check what is APP.$rootElement.contains(cache.el)
|
|
29
|
-
if (!handlerName || (!forceRender && !APP.$rootElement.contains(cache.el))) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const handlers = getViewModelValue(viewModel, handlerName);
|
|
34
|
-
|
|
35
|
-
if (handlers && typeof handlers[inHandlerName] === 'function' && typeof handlers[outHandlerName] === 'function') {
|
|
36
|
-
viewModelContext = resolveViewModelContext(viewModel, handlerName);
|
|
37
|
-
paramList = paramList ? resolveParamList(viewModel, paramList) : [];
|
|
38
|
-
|
|
39
|
-
function onMouseEnterHandler(e) {
|
|
40
|
-
const args = [e, cache.el].concat(paramList);
|
|
41
|
-
handlers[inHandlerName].apply(viewModelContext, args);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function onMouseLeaveHandler(e) {
|
|
45
|
-
const args = [e, cache.el].concat(paramList);
|
|
46
|
-
handlers[outHandlerName].apply(viewModelContext, args);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
cache.el.removeEventListener('mouseenter', onMouseEnterHandler, false);
|
|
50
|
-
cache.el.removeEventListener('mouseleave', onMouseLeaveHandler, false);
|
|
51
|
-
|
|
52
|
-
cache.el.addEventListener('mouseenter', onMouseEnterHandler, false);
|
|
53
|
-
cache.el.addEventListener('mouseleave', onMouseLeaveHandler, false);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export default hoverBinding;
|
package/src/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as config from './config';
|
|
2
|
-
import {extend} from './util';
|
|
3
|
-
import Binder from './binder';
|
|
4
|
-
|
|
5
|
-
const isSupportPromise = typeof window['Promise'] === 'function';
|
|
6
|
-
|
|
7
|
-
let bindingAttrs = config.bindingAttrs;
|
|
8
|
-
|
|
9
|
-
const use = (settings = {}) => {
|
|
10
|
-
if (settings.bindingAttrs) {
|
|
11
|
-
bindingAttrs = extend({}, settings.bindingAttrs);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const init = ($rootElement, viewModel = null) => {
|
|
16
|
-
if (!isSupportPromise) {
|
|
17
|
-
return console.warn('Browser not support Promise');
|
|
18
|
-
}
|
|
19
|
-
return new Binder($rootElement, viewModel, bindingAttrs);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default {
|
|
23
|
-
use: use,
|
|
24
|
-
init: init,
|
|
25
|
-
version: '@version@',
|
|
26
|
-
};
|
package/src/renderTemplate.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {dataIndexAttr} from './config';
|
|
2
|
-
import {
|
|
3
|
-
createHtmlFragment,
|
|
4
|
-
emptyElement,
|
|
5
|
-
getViewModelPropValue,
|
|
6
|
-
parseStringToJson,
|
|
7
|
-
} from './util';
|
|
8
|
-
|
|
9
|
-
let $domFragment = null;
|
|
10
|
-
let $templateRoot = null;
|
|
11
|
-
let nestTemplatesCount = 0;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* getTemplateString
|
|
15
|
-
* @description get Template tag innerHTML string
|
|
16
|
-
* @param {string} id
|
|
17
|
-
* @return {string} rendered html string
|
|
18
|
-
*/
|
|
19
|
-
const getTemplateString = (id) => {
|
|
20
|
-
const templateElement = document.getElementById(id);
|
|
21
|
-
|
|
22
|
-
return templateElement ? templateElement.innerHTML : '';
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* renderTemplate
|
|
27
|
-
* @description
|
|
28
|
-
* get template setting from DOM attribute then call compileTemplate
|
|
29
|
-
* to render and append to target DOM
|
|
30
|
-
* @param {object} cache
|
|
31
|
-
* @param {object} viewModel
|
|
32
|
-
* @param {object} bindingAttrs
|
|
33
|
-
* @param {object} elementCache
|
|
34
|
-
*/
|
|
35
|
-
const renderTemplate = (cache, viewModel, bindingAttrs, elementCache) => {
|
|
36
|
-
const settings = typeof cache.dataKey === 'string' ? parseStringToJson(cache.dataKey) : cache.dataKey;
|
|
37
|
-
let viewData = settings.data;
|
|
38
|
-
const isAppend = settings.append;
|
|
39
|
-
const isPrepend = settings.prepend;
|
|
40
|
-
let $currentElement;
|
|
41
|
-
|
|
42
|
-
cache.dataKey = settings;
|
|
43
|
-
|
|
44
|
-
viewData = (typeof viewData === 'undefined' || viewData === '$root') ?
|
|
45
|
-
viewModel :
|
|
46
|
-
getViewModelPropValue(viewModel, {
|
|
47
|
-
dataKey: settings.data,
|
|
48
|
-
parameters: cache.parameters,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (!viewData) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const $element = cache.el;
|
|
56
|
-
const $index = typeof viewModel.$index !== 'undefined' ? viewModel.$index : $element.getAttribute(dataIndexAttr);
|
|
57
|
-
|
|
58
|
-
if (typeof $index !== 'undefined') {
|
|
59
|
-
viewData.$index = $index;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
$domFragment = $domFragment || document.createDocumentFragment();
|
|
63
|
-
|
|
64
|
-
$templateRoot = $templateRoot || $element;
|
|
65
|
-
|
|
66
|
-
const htmlString = getTemplateString(settings.id);
|
|
67
|
-
|
|
68
|
-
const htmlFragment = createHtmlFragment(htmlString);
|
|
69
|
-
|
|
70
|
-
// append rendered html
|
|
71
|
-
if (!$domFragment.childNodes.length) {
|
|
72
|
-
// domFragment should be empty in first run
|
|
73
|
-
$currentElement = $domFragment; // copy of $domFragment for later find nested template check
|
|
74
|
-
$domFragment.appendChild(htmlFragment);
|
|
75
|
-
} else {
|
|
76
|
-
// during recursive run keep append to current fragment
|
|
77
|
-
$currentElement = $element; // reset to current nested template element
|
|
78
|
-
if (!isAppend && !isPrepend) {
|
|
79
|
-
$currentElement = emptyElement($currentElement);
|
|
80
|
-
}
|
|
81
|
-
if (isPrepend) {
|
|
82
|
-
$currentElement.insertBefore(htmlFragment, $currentElement.firstChild);
|
|
83
|
-
} else {
|
|
84
|
-
$currentElement.appendChild(htmlFragment);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// check if there are nested template then recurisive render them
|
|
89
|
-
const $nestedTemplates = $currentElement.querySelectorAll('[' + bindingAttrs.tmp + ']');
|
|
90
|
-
|
|
91
|
-
const nestedTemplatesLength = $nestedTemplates.length;
|
|
92
|
-
|
|
93
|
-
if (nestedTemplatesLength) {
|
|
94
|
-
nestTemplatesCount += nestedTemplatesLength;
|
|
95
|
-
|
|
96
|
-
for (let i=0; i < nestedTemplatesLength; i+=1) {
|
|
97
|
-
const thisTemplateCache = {
|
|
98
|
-
el: $nestedTemplates[i],
|
|
99
|
-
dataKey: $nestedTemplates[i].getAttribute(bindingAttrs.tmp),
|
|
100
|
-
};
|
|
101
|
-
elementCache[bindingAttrs.tmp].push(thisTemplateCache);
|
|
102
|
-
// recursive template render
|
|
103
|
-
renderTemplate(thisTemplateCache, viewModel, bindingAttrs, elementCache);
|
|
104
|
-
nestTemplatesCount -= 1;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// no more nested tempalted to render, start to append $domFragment into $templateRoot
|
|
109
|
-
if (nestTemplatesCount === 0) {
|
|
110
|
-
// append to DOM once
|
|
111
|
-
if (!isAppend && !isPrepend) {
|
|
112
|
-
$templateRoot = emptyElement($templateRoot);
|
|
113
|
-
}
|
|
114
|
-
if (isPrepend) {
|
|
115
|
-
$templateRoot.insertBefore($domFragment, $templateRoot.firstChild);
|
|
116
|
-
} else {
|
|
117
|
-
$templateRoot.appendChild($domFragment);
|
|
118
|
-
}
|
|
119
|
-
// clear cached fragment
|
|
120
|
-
$domFragment = $templateRoot = null;
|
|
121
|
-
// trigger callback if provided
|
|
122
|
-
if (typeof viewModel.afterTemplateRender === 'function') {
|
|
123
|
-
viewModel.afterTemplateRender(viewData);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export default renderTemplate;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {bindingUpdateConditions} from './config';
|
|
2
|
-
import applyBinding from './applyBindingExport';
|
|
3
|
-
import createBindingOption from './createBindingOption';
|
|
4
|
-
import renderTemplate from './renderTemplate';
|
|
5
|
-
|
|
6
|
-
const renderTemplatesBinding = ({ctx, elementCache, updateOption, bindingAttrs, viewModel}) => {
|
|
7
|
-
if (!elementCache || !bindingAttrs) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
// render and apply binding to template(s) and forOf DOM
|
|
11
|
-
if (elementCache[bindingAttrs.tmp] && elementCache[bindingAttrs.tmp].length) {
|
|
12
|
-
// when re-render call with {templateBinding: true}
|
|
13
|
-
// template and nested templates
|
|
14
|
-
if (updateOption.templateBinding) {
|
|
15
|
-
// overwrite updateOption with 'init' bindingUpdateConditions
|
|
16
|
-
updateOption = createBindingOption(bindingUpdateConditions.init);
|
|
17
|
-
|
|
18
|
-
elementCache[bindingAttrs.tmp].forEach(($element) => {
|
|
19
|
-
renderTemplate($element, viewModel, bindingAttrs, elementCache);
|
|
20
|
-
});
|
|
21
|
-
// update cache after all template(s) rendered
|
|
22
|
-
ctx.updateElementCache({
|
|
23
|
-
templateCache: true,
|
|
24
|
-
elementCache: elementCache,
|
|
25
|
-
isRenderedTemplates: true,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
// enforce render even element is not in DOM tree
|
|
29
|
-
updateOption.forceRender = true;
|
|
30
|
-
|
|
31
|
-
// apply bindings to rendered templates element
|
|
32
|
-
elementCache[bindingAttrs.tmp].forEach((cache) => {
|
|
33
|
-
applyBinding({
|
|
34
|
-
elementCache: cache.bindingCache,
|
|
35
|
-
updateOption: updateOption,
|
|
36
|
-
bindingAttrs: bindingAttrs,
|
|
37
|
-
viewModel: viewModel,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default renderTemplatesBinding;
|