apprun 4.0.0 → 6.0.0-rc.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/CHANGELOG.md +235 -12
- package/LICENSE +1 -1
- package/README.md +225 -110
- package/apprun.d.ts +240 -34
- package/cli/app.js +29 -0
- package/cli/colors.js +69 -0
- package/cli/index.html +13 -0
- package/cli/index.js +96 -0
- package/dist/apprun-code.js +2 -0
- package/dist/apprun-code.js.map +1 -0
- package/dist/apprun-dev-tools.js +1 -1
- package/dist/apprun-dev-tools.js.map +1 -1
- package/dist/apprun-html.esm.js +34 -0
- package/dist/apprun-html.esm.js.map +1 -0
- package/dist/apprun-html.js +2 -1
- package/dist/apprun-html.js.LICENSE.txt +11 -0
- package/dist/apprun-html.js.map +1 -1
- package/dist/apprun-play.js +2 -0
- package/dist/apprun-play.js.map +1 -0
- package/dist/apprun.esm.js +2 -0
- package/dist/apprun.esm.js.map +1 -0
- package/dist/apprun.js +1 -1
- package/dist/apprun.js.map +1 -1
- package/dist/createState.js +2 -0
- package/dist/createState.js.map +1 -0
- package/esm/add-components.js +90 -0
- package/esm/add-components.js.map +1 -0
- package/esm/app.js +209 -0
- package/esm/app.js.map +1 -0
- package/esm/apprun-code.js +170 -0
- package/esm/apprun-code.js.map +1 -0
- package/esm/apprun-dev-tools-tests.js +95 -0
- package/esm/apprun-dev-tools-tests.js.map +1 -0
- package/esm/apprun-dev-tools.js +281 -0
- package/esm/apprun-dev-tools.js.map +1 -0
- package/esm/apprun-html.js +24 -0
- package/esm/apprun-html.js.map +1 -0
- package/esm/apprun-play.js +248 -0
- package/esm/apprun-play.js.map +1 -0
- package/esm/apprun.js +220 -0
- package/esm/apprun.js.map +1 -0
- package/esm/component.js +413 -0
- package/esm/component.js.map +1 -0
- package/esm/createState.js +9 -0
- package/esm/createState.js.map +1 -0
- package/esm/decorator.js +88 -0
- package/esm/decorator.js.map +1 -0
- package/esm/directive.js +306 -0
- package/esm/directive.js.map +1 -0
- package/esm/router.js +345 -0
- package/esm/router.js.map +1 -0
- package/esm/type-utils.js +90 -0
- package/esm/type-utils.js.map +1 -0
- package/esm/types.js +58 -0
- package/esm/types.js.map +1 -0
- package/esm/vdom-lit-html.js +65 -0
- package/esm/vdom-lit-html.js.map +1 -0
- package/esm/vdom-my-prop-attr.js +227 -0
- package/esm/vdom-my-prop-attr.js.map +1 -0
- package/esm/vdom-my.js +293 -0
- package/esm/vdom-my.js.map +1 -0
- package/esm/vdom-to-html.js +54 -0
- package/esm/vdom-to-html.js.map +1 -0
- package/esm/vdom.js +28 -0
- package/esm/vdom.js.map +1 -0
- package/esm/version.js +15 -0
- package/esm/version.js.map +1 -0
- package/esm/web-component.js +155 -0
- package/esm/web-component.js.map +1 -0
- package/jsx-runtime.js +2 -0
- package/jsx-runtime.js.map +1 -0
- package/package.json +90 -41
- package/.travis.yml +0 -10
- package/.vscode/launch.json +0 -19
- package/BACKERS.md +0 -3
- package/apprun-cli.js +0 -177
- package/cli-templates/_gitignore +0 -6
- package/cli-templates/component.ts_ +0 -16
- package/cli-templates/index.html +0 -11
- package/cli-templates/karma.conf.js +0 -24
- package/cli-templates/main.ts_ +0 -13
- package/cli-templates/readme.md +0 -7
- package/cli-templates/spa_index.html +0 -14
- package/cli-templates/spa_main.ts_ +0 -47
- package/cli-templates/spec.ts_ +0 -11
- package/cli-templates/tsconfig.json +0 -12
- package/cli-templates/webpack.config.js +0 -23
- package/demo-html/app.js +0 -2
- package/demo-html/app.js.map +0 -1
- package/demo-html/counter-c.html +0 -29
- package/demo-html/counter-wc-event.html +0 -29
- package/demo-html/counter-wc.html +0 -29
- package/demo-html/counter.html +0 -26
- package/demo-html/index.html +0 -14
- package/demo-html/main.tsx +0 -31
- package/docs/README.md +0 -326
- package/docs/index.html +0 -23
- package/index.html +0 -85
- package/logo.png +0 -0
- package/src/app.ts +0 -69
- package/src/apprun-dev-tools.tsx +0 -67
- package/src/apprun-html.ts +0 -13
- package/src/apprun.ts +0 -53
- package/src/component.ts +0 -189
- package/src/createComponent.tsx +0 -38
- package/src/decorator.ts +0 -36
- package/src/router.ts +0 -19
- package/src/types.ts +0 -9
- package/src/vdom-html.ts +0 -17
- package/src/vdom-my.ts +0 -191
- package/src/vdom-to-html.tsx +0 -45
- package/src/vdom.ts +0 -7
- package/src/web-component.ts +0 -29
- package/tests/app-rx.spec_ +0 -41
- package/tests/app.spec.ts +0 -122
- package/tests/application.spec.tsx +0 -23
- package/tests/component.spec.tsx +0 -296
- package/tests/custom-element.spec.tsx +0 -19
- package/tests/data-attr.spec.tsx +0 -42
- package/tests/decorator.spec.tsx +0 -104
- package/tests/fragment.spec.tsx +0 -79
- package/tests/hyperscript.spec.ts +0 -43
- package/tests/node-test.js +0 -7
- package/tests/router.spec.ts +0 -69
- package/tests/stateful-component.spec.tsx +0 -248
- package/tests/typed.spec.tsx +0 -63
- package/tests/vdom-html.spec.ts +0 -35
- package/tests/vdom-jsx.spec.tsx +0 -131
- package/tests/vdom-my.spec.tsx +0 -195
- package/tests/view-engine.spec.js +0 -59
- package/tsconfig.json +0 -11
- package/tslint.json +0 -124
- package/typescriptreact.json +0 -87
- package/viewEngine.js +0 -54
- package/webpack.config.js +0 -30
package/tests/app.spec.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { App } from '../src/app';
|
|
2
|
-
|
|
3
|
-
describe('app events', () => {
|
|
4
|
-
|
|
5
|
-
it('should be able to register(on) and trigger(run)', () => {
|
|
6
|
-
const app = new App();
|
|
7
|
-
let hi_called = false;
|
|
8
|
-
app.on('hi', () => {
|
|
9
|
-
hi_called = true;
|
|
10
|
-
});
|
|
11
|
-
app.run('hi');
|
|
12
|
-
expect(hi_called).toBeTruthy();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should pass parameters to execution', () => {
|
|
16
|
-
const app = new App();
|
|
17
|
-
let hi_called = false;
|
|
18
|
-
app.on('hi', (p1, p2, p3, p4) => {
|
|
19
|
-
hi_called = true;
|
|
20
|
-
expect(p1).toBe(1);
|
|
21
|
-
expect(p2).toBe('xx');
|
|
22
|
-
expect(p3).toBeNull;
|
|
23
|
-
expect(p4).toEqual({a:1});
|
|
24
|
-
});
|
|
25
|
-
app.run('hi', 1, 'xx', null, {a: 1});
|
|
26
|
-
expect(hi_called).toBeTruthy();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should take once option', () => {
|
|
30
|
-
const app = new App();
|
|
31
|
-
app.on('hi', (p1, p2, p3, p4) => { }, { once: true });
|
|
32
|
-
app.run('hi', 1, 'xx', null, { a: 1 });
|
|
33
|
-
expect(app['_events']['hi']).toBeUndefined();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should run once', () => {
|
|
37
|
-
const app = new App();
|
|
38
|
-
app.once('hi1', (p1, p2, p3, p4) => { });
|
|
39
|
-
app.run('hi1', 1, 'xx', null, { a: 1 });
|
|
40
|
-
expect(app['_events']['hi1']).toBeUndefined();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should allow off', () => {
|
|
44
|
-
const app = new App();
|
|
45
|
-
const fn = (a) => {}
|
|
46
|
-
app.on('hi', fn);
|
|
47
|
-
app.off('hi', fn);
|
|
48
|
-
expect(app['_events']['hi']).toBeUndefined();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should take delay option', (done) => {
|
|
52
|
-
const app = new App();
|
|
53
|
-
let i = 0;
|
|
54
|
-
app.on('hi', () => { i++; }, {delay: 200});
|
|
55
|
-
app.run('hi');
|
|
56
|
-
app.run('hi');
|
|
57
|
-
app.run('hi');
|
|
58
|
-
expect(i).toBe(0);
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
expect(i).toBe(1);
|
|
61
|
-
done();
|
|
62
|
-
}, 250);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should mix delay and non-delay events', (done) => {
|
|
66
|
-
const app = new App();
|
|
67
|
-
let i = 0;
|
|
68
|
-
let j = 0;
|
|
69
|
-
app.on('hi', () => { j++; });
|
|
70
|
-
app.on('hi', () => { i++; }, {delay: 200});
|
|
71
|
-
app.run('hi');
|
|
72
|
-
app.run('hi');
|
|
73
|
-
app.run('hi');
|
|
74
|
-
expect(i).toBe(0);
|
|
75
|
-
expect(j).toBe(3);
|
|
76
|
-
setTimeout(() => {
|
|
77
|
-
expect(i).toBe(1);
|
|
78
|
-
done();
|
|
79
|
-
}, 250);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should mix delay and once option', (done) => {
|
|
83
|
-
const app = new App();
|
|
84
|
-
spyOn(console, 'assert');
|
|
85
|
-
let i = 0;
|
|
86
|
-
app.on('hi', () => { i++; }, {one: true, delay: 200});
|
|
87
|
-
app.run('hi');
|
|
88
|
-
app.run('hi');
|
|
89
|
-
app.run('hi');
|
|
90
|
-
expect(i).toBe(0);
|
|
91
|
-
setTimeout(() => {
|
|
92
|
-
expect(i).toBe(1);
|
|
93
|
-
expect(console.assert).toHaveBeenCalled();
|
|
94
|
-
done();
|
|
95
|
-
}, 250);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should remove only subscription that is once', () => {
|
|
99
|
-
const app = new App();
|
|
100
|
-
spyOn(console, 'assert');
|
|
101
|
-
spyOn(console, 'log');
|
|
102
|
-
app.on('hi', () => {
|
|
103
|
-
console.log('hi');
|
|
104
|
-
});
|
|
105
|
-
app.on('hi', () => {}, {once: true});
|
|
106
|
-
app.run('hi');
|
|
107
|
-
app.run('hi');
|
|
108
|
-
expect(console.log).toHaveBeenCalledTimes(2);
|
|
109
|
-
expect(console.assert).toHaveBeenCalled();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
it('should run only once', () => {
|
|
114
|
-
const app = new App();
|
|
115
|
-
spyOn(console, 'assert');
|
|
116
|
-
app.on('hi', (p1, p2, p3, p4) => {}, {once: true});
|
|
117
|
-
app.run('hi', 1, 'xx', null, {a: 1});
|
|
118
|
-
app.run('hi', 1, 'xx', null, {a: 1});
|
|
119
|
-
expect(console.assert).toHaveBeenCalled();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import app, { Component } from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
describe('app.start', () => {
|
|
4
|
-
it('should allow no parameters', () => {
|
|
5
|
-
app.start()
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
it('should allow empty element', () => {
|
|
9
|
-
app.start('')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('should allow null element', () => {
|
|
13
|
-
app.start(null)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('should allow only element, state', () => {
|
|
17
|
-
app.start('', null)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should allow null state, view, update', () => {
|
|
21
|
-
app.start('', null, s=>s)
|
|
22
|
-
})
|
|
23
|
-
})
|
package/tests/component.spec.tsx
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import app, { Component } from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
app.on('hi', _ => { })
|
|
4
|
-
app.on('debug', _ => { });
|
|
5
|
-
|
|
6
|
-
class TestComponent extends Component {
|
|
7
|
-
|
|
8
|
-
state = 'x';
|
|
9
|
-
view = (state) => state
|
|
10
|
-
|
|
11
|
-
update = {
|
|
12
|
-
'hi': (state, value) => value,
|
|
13
|
-
'#hi': (state, value) => value,
|
|
14
|
-
'hiNull': (state, value) => null,
|
|
15
|
-
'hiAsync': async (state, value) => {
|
|
16
|
-
return new Promise(resolve => {
|
|
17
|
-
resolve(value);
|
|
18
|
-
})
|
|
19
|
-
},
|
|
20
|
-
'hiAsyncNull': async (state, value) => {
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
rendered = () => { }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('Component', () => {
|
|
27
|
-
|
|
28
|
-
let component;
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
component = new TestComponent();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should allow element to be undefined', () => {
|
|
34
|
-
spyOn(component, 'view');
|
|
35
|
-
expect(component.element).toBeUndefined()
|
|
36
|
-
expect(component.view).not.toHaveBeenCalled();
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should trigger view when mounted with render option', () => {
|
|
40
|
-
spyOn(component, 'view');
|
|
41
|
-
component.mount(document.body, { render: true });
|
|
42
|
-
expect(component.element).toBe(document.body);
|
|
43
|
-
expect(component.view).toHaveBeenCalled();
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('should not trigger view when mounted', () => {
|
|
47
|
-
spyOn(component, 'view');
|
|
48
|
-
component.mount(document.body);
|
|
49
|
-
expect(component.element).toBe(document.body);
|
|
50
|
-
expect(component.view).not.toHaveBeenCalled();
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('should trigger view when started', () => {
|
|
54
|
-
spyOn(component, 'view');
|
|
55
|
-
component.start(document.body);
|
|
56
|
-
expect(component.element).toBe(document.body);
|
|
57
|
-
expect(component.view).toHaveBeenCalled();
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should not trigger when update returns null or undefined', () => {
|
|
61
|
-
component.mount(document.body);
|
|
62
|
-
spyOn(component, 'view');
|
|
63
|
-
component.run('hi', null);
|
|
64
|
-
expect(component.view).not.toHaveBeenCalled();
|
|
65
|
-
component.run('hiNull');
|
|
66
|
-
expect(component.view).not.toHaveBeenCalled();
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('should not trigger view when update returns null or undefined with async', () => {
|
|
70
|
-
component.mount(document.body);
|
|
71
|
-
spyOn(component, 'view');
|
|
72
|
-
component.run('hiAsync', null);
|
|
73
|
-
expect(component.view).not.toHaveBeenCalledWith(); //Promise
|
|
74
|
-
expect(component.state).not.toBeNull();
|
|
75
|
-
component.run('hiAsyncNull');
|
|
76
|
-
expect(component.view).not.toHaveBeenCalledWith(); //Promise
|
|
77
|
-
expect(component.state).not.toBeNull();
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('should handle local events', () => {
|
|
81
|
-
component.mount(document.body);
|
|
82
|
-
spyOn(component, 'view');
|
|
83
|
-
component.run('hi', '');
|
|
84
|
-
expect(component.view).toHaveBeenCalled();
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('should not handle unknown global events', () => {
|
|
88
|
-
component.mount(document.body);
|
|
89
|
-
spyOn(component, 'view');
|
|
90
|
-
app.run('hi');
|
|
91
|
-
expect(component.view).not.toHaveBeenCalled();
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should handle global events', () => {
|
|
95
|
-
component.mount(document.body);
|
|
96
|
-
spyOn(component, 'view');
|
|
97
|
-
app.run('#hi', '');
|
|
98
|
-
expect(component.view).toHaveBeenCalled();
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
it('should track history', () => {
|
|
103
|
-
component.start(document.body, { history: true });
|
|
104
|
-
expect(component.state).toBe('x');
|
|
105
|
-
component.run('hi', 'xx');
|
|
106
|
-
expect(component.state).toBe('xx');
|
|
107
|
-
component.run('hi', 'xxx');
|
|
108
|
-
expect(component.state).toBe('xxx');
|
|
109
|
-
component.run('history-prev');
|
|
110
|
-
expect(component.state).toBe('xx');
|
|
111
|
-
component.run('history-next');
|
|
112
|
-
expect(component.state).toBe('xxx');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should track history with custom event name', () => {
|
|
116
|
-
component.start(document.body, { history: { prev: 'prev', next: 'next' } });
|
|
117
|
-
expect(component.state).toBe('x');
|
|
118
|
-
component.run('hi', 'xx');
|
|
119
|
-
expect(component.state).toBe('xx');
|
|
120
|
-
component.run('hi', 'xxx');
|
|
121
|
-
expect(component.state).toBe('xxx');
|
|
122
|
-
component.run('prev');
|
|
123
|
-
expect(component.state).toBe('xx');
|
|
124
|
-
component.run('next');
|
|
125
|
-
expect(component.state).toBe('xxx');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should track history with global custom event name', () => {
|
|
129
|
-
spyOn(component, 'view');
|
|
130
|
-
component.mount(document.body, { render: true, history: { prev: 'prev', next: 'next' }, global_event: true });
|
|
131
|
-
expect(component.state).toBe('x');
|
|
132
|
-
app.run('hi', 'xx');
|
|
133
|
-
expect(component.state).toBe('xx');
|
|
134
|
-
app.run('hi', 'xxx');
|
|
135
|
-
expect(component.state).toBe('xxx');
|
|
136
|
-
app.run('prev');
|
|
137
|
-
expect(component.state).toBe('xx');
|
|
138
|
-
app.run('next');
|
|
139
|
-
expect(component.state).toBe('xxx');
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should call rendered function', () => {
|
|
144
|
-
const spy = jasmine.createSpy('spy');
|
|
145
|
-
component.rendered = state => spy(state);
|
|
146
|
-
component.start(document.body);
|
|
147
|
-
expect(spy).toHaveBeenCalledWith('x');
|
|
148
|
-
component.run('hi', 'abc');
|
|
149
|
-
expect(spy).toHaveBeenCalledWith('abc');
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('should handle async update', (done) => {
|
|
153
|
-
const fn = async () => new Promise((resolve, reject) => {
|
|
154
|
-
window.setTimeout(() => {
|
|
155
|
-
resolve('xx');
|
|
156
|
-
}, 10);
|
|
157
|
-
});
|
|
158
|
-
const spy = jasmine.createSpy('spy');
|
|
159
|
-
class Test extends Component {
|
|
160
|
-
state = -1;
|
|
161
|
-
view = state => spy(state);
|
|
162
|
-
update = {
|
|
163
|
-
method1: async (...args) => {
|
|
164
|
-
const v = await fn();
|
|
165
|
-
return v;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const t = new Test().start();
|
|
170
|
-
t.run('method1')
|
|
171
|
-
window.setTimeout(() => {
|
|
172
|
-
const callArgs = spy.calls.allArgs();
|
|
173
|
-
expect(callArgs[0][0]).toBe(-1);
|
|
174
|
-
expect(callArgs[1][0]).toBe('xx');
|
|
175
|
-
done()
|
|
176
|
-
}, 20);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should support tuple in update', () => {
|
|
180
|
-
let i = 0;
|
|
181
|
-
class Test extends Component {
|
|
182
|
-
state = -1;
|
|
183
|
-
|
|
184
|
-
update = {
|
|
185
|
-
'method1': [_ => i++, { once: true }],
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const t = new Test().start();
|
|
190
|
-
t.run('method1');
|
|
191
|
-
// t.run('method1');
|
|
192
|
-
// t.run('method1');
|
|
193
|
-
|
|
194
|
-
expect(i).toEqual(1);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should support async tuple in update', (done) => {
|
|
198
|
-
let i = 0;
|
|
199
|
-
const fn = async () => new Promise<string>((resolve) => {
|
|
200
|
-
window.setTimeout(() => {
|
|
201
|
-
resolve('xx');
|
|
202
|
-
}, 10);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
class Test extends Component {
|
|
206
|
-
state = -1;
|
|
207
|
-
|
|
208
|
-
update = {
|
|
209
|
-
'method1': [async _ => {
|
|
210
|
-
const t = await fn();
|
|
211
|
-
i++
|
|
212
|
-
},
|
|
213
|
-
{ once: true }],
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const t = new Test().start();
|
|
218
|
-
t.run('method1');
|
|
219
|
-
// t.run('method1');
|
|
220
|
-
// t.run('method1');
|
|
221
|
-
|
|
222
|
-
window.setTimeout(() => {
|
|
223
|
-
expect(i).toBe(1);
|
|
224
|
-
done();
|
|
225
|
-
}, 20)
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('should support update alias', () => {
|
|
229
|
-
let i = 0;
|
|
230
|
-
class Test extends Component {
|
|
231
|
-
state = -1;
|
|
232
|
-
update = {
|
|
233
|
-
'method1, m1, m2, #m3': [_ => ++i, {}]
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const t = new Test().start();
|
|
237
|
-
t.run('method1');
|
|
238
|
-
t.run('m1');
|
|
239
|
-
t.run('m2');
|
|
240
|
-
app.run('#m3');
|
|
241
|
-
|
|
242
|
-
expect(i).toBe(4);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('should support call back', () => {
|
|
246
|
-
let i = 0;
|
|
247
|
-
class Test extends Component {
|
|
248
|
-
state = -1;
|
|
249
|
-
update = {
|
|
250
|
-
'method1': [_ => ++i, { callback: _ => ++i }]
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const t = new Test().start();
|
|
254
|
-
t.run('method1');
|
|
255
|
-
expect(i).toBe(2);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should support options', () => {
|
|
259
|
-
class Test extends Component {
|
|
260
|
-
view = (state) => state
|
|
261
|
-
update = {
|
|
262
|
-
'method1': [(state, val) => val, { render: false }]
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const t = new Test();
|
|
266
|
-
t.start(document.body);
|
|
267
|
-
spyOn(t, 'view');
|
|
268
|
-
t.run('method1', 'x');
|
|
269
|
-
expect(t.view).not.toHaveBeenCalled();
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
it('should support call back, alias and options', () => {
|
|
273
|
-
let i = 0;
|
|
274
|
-
class Test extends Component {
|
|
275
|
-
state = -1;
|
|
276
|
-
update = {
|
|
277
|
-
'method1, m1, m2, #m3': [_ => ++i, { callback: _ => ++i }]
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const t = new Test().start();
|
|
281
|
-
t.run('method1');
|
|
282
|
-
t.run('m1');
|
|
283
|
-
t.run('m2');
|
|
284
|
-
app.run('#m3');
|
|
285
|
-
|
|
286
|
-
expect(i).toBe(8);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('should save/attach component to element', () => {
|
|
290
|
-
component.start(document.body);
|
|
291
|
-
expect(document.body['_component']).toBe(component);
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import app, { Component } from '../src/apprun';
|
|
2
|
-
import { customElement } from '../src/web-component';
|
|
3
|
-
|
|
4
|
-
describe('web-component', () => {
|
|
5
|
-
it('should convert component to custom element', () => {
|
|
6
|
-
class C extends Component {
|
|
7
|
-
state = 50;
|
|
8
|
-
}
|
|
9
|
-
// const component = new (customElement(C)); // need TypeScript 2.9?
|
|
10
|
-
|
|
11
|
-
// class CE extends customElement(C) { }
|
|
12
|
-
// const component = new CE();
|
|
13
|
-
// expect(component.state).toBe(5);
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('should have on and run fuction', () => {
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
-
})
|
package/tests/data-attr.spec.tsx
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import app from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
describe('vdom-my', () => {
|
|
4
|
-
it('should set data attribute', () => {
|
|
5
|
-
const el = document.createElement('div');
|
|
6
|
-
const view = () => <div data-a='a'></div>
|
|
7
|
-
app.render(el, view());
|
|
8
|
-
const div = el.firstElementChild as HTMLDivElement;
|
|
9
|
-
expect(div.dataset.a).toBe('a');
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('should unset data attribute', () => {
|
|
13
|
-
const el = document.createElement('div');
|
|
14
|
-
const view1 = () => <div data-a='b'></div>
|
|
15
|
-
const view2 = () => <div></div>
|
|
16
|
-
app.render(el, view1());
|
|
17
|
-
const div = el.firstElementChild as HTMLDivElement;
|
|
18
|
-
expect(div.dataset.a).toBe('b');
|
|
19
|
-
app.render(el, view2());
|
|
20
|
-
expect(div.dataset.a).toBe('');
|
|
21
|
-
})
|
|
22
|
-
it('should attribute - role', () => {
|
|
23
|
-
const el = document.createElement('div');
|
|
24
|
-
const view1 = () => <div role='r'></div>
|
|
25
|
-
const view2 = () => <div></div>
|
|
26
|
-
app.render(el, view1());
|
|
27
|
-
const div = el.firstElementChild as HTMLDivElement;
|
|
28
|
-
expect(div.getAttribute('role')).toBe('r');
|
|
29
|
-
app.render(el, view2());
|
|
30
|
-
expect(div.getAttribute('role')).toBe('');
|
|
31
|
-
})
|
|
32
|
-
it('should attribute - aria', () => {
|
|
33
|
-
const el = document.createElement('div');
|
|
34
|
-
const view1 = () => <div aria-label='al'></div>
|
|
35
|
-
const view2 = () => <div></div>
|
|
36
|
-
app.render(el, view1());
|
|
37
|
-
const div = el.firstElementChild as HTMLDivElement;
|
|
38
|
-
expect(div.getAttribute('aria-label')).toBe('al');
|
|
39
|
-
app.render(el, view2());
|
|
40
|
-
expect(div.getAttribute('aria-label')).toBe('');
|
|
41
|
-
})
|
|
42
|
-
})
|
package/tests/decorator.spec.tsx
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import app, { Component, on, update, event } from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
describe('Update decorator', () => {
|
|
4
|
-
|
|
5
|
-
it('should convert class method to action using @update', () => {
|
|
6
|
-
class TestComponent extends Component {
|
|
7
|
-
view = state => state
|
|
8
|
-
|
|
9
|
-
@update()
|
|
10
|
-
f1(state, val) {
|
|
11
|
-
return val;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@event('hi, #hi')
|
|
15
|
-
f2(state, val) {
|
|
16
|
-
return val;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const test = new TestComponent().mount();
|
|
21
|
-
const spy = spyOn(test, 'view')
|
|
22
|
-
test.run('f1', 'x')
|
|
23
|
-
expect(spy).toHaveBeenCalledWith('x')
|
|
24
|
-
// test.run('f2', 'xx')
|
|
25
|
-
// expect(spy).not.toHaveBeenCalledWith('xx')
|
|
26
|
-
// local alias
|
|
27
|
-
test.run('hi', 'xxx')
|
|
28
|
-
expect(spy).toHaveBeenCalledWith('xxx')
|
|
29
|
-
// global alias
|
|
30
|
-
app.run('#hi', 'xxxx')
|
|
31
|
-
expect(spy).toHaveBeenCalledWith('xxxx')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
it('should convert class property to action using @on', () => {
|
|
36
|
-
class TestComponent extends Component {
|
|
37
|
-
view = state => state
|
|
38
|
-
|
|
39
|
-
@on()
|
|
40
|
-
f1 = (state, val) => val
|
|
41
|
-
|
|
42
|
-
@on('hi2, #hi2')
|
|
43
|
-
f2 = (state, val) => val
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const test = new TestComponent().mount();
|
|
47
|
-
const spy = spyOn(test, 'view')
|
|
48
|
-
test.run('f1', 'x')
|
|
49
|
-
expect(spy).toHaveBeenCalledWith('x')
|
|
50
|
-
// test.run('f2', 'xx')
|
|
51
|
-
// expect(spy).not.toHaveBeenCalledWith('xx')
|
|
52
|
-
// local alias
|
|
53
|
-
test.run('hi2', 'xxx')
|
|
54
|
-
expect(spy).toHaveBeenCalledWith('xxx')
|
|
55
|
-
// global alias
|
|
56
|
-
app.run('#hi2', 'xxxx')
|
|
57
|
-
expect(spy).toHaveBeenCalledWith('xxxx')
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('should support this in @on with =>', done => {
|
|
62
|
-
class TestComponent extends Component {
|
|
63
|
-
view = state => state
|
|
64
|
-
|
|
65
|
-
@on('test')
|
|
66
|
-
f1 = (state, val) => {
|
|
67
|
-
expect(this).not.toBeUndefined();
|
|
68
|
-
done();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const test = new TestComponent().mount();
|
|
72
|
-
test.run('test');
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should support this in @on with function', done => {
|
|
76
|
-
class TestComponent extends Component {
|
|
77
|
-
view = state => state
|
|
78
|
-
|
|
79
|
-
@on('test')
|
|
80
|
-
f1 = function (state, val) {
|
|
81
|
-
expect(this).not.toBeUndefined();
|
|
82
|
-
done();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const test = new TestComponent().mount();
|
|
86
|
-
test.run('test');
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should support this in @update', done => {
|
|
90
|
-
class TestComponent extends Component {
|
|
91
|
-
view = state => state
|
|
92
|
-
|
|
93
|
-
@update('test')
|
|
94
|
-
onTest(state, val) {
|
|
95
|
-
expect(this).not.toBeUndefined();
|
|
96
|
-
done();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const test = new TestComponent().mount();
|
|
100
|
-
test.run('test');
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
})
|
package/tests/fragment.spec.tsx
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import app from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
describe('vdom-my', () => {
|
|
4
|
-
it('should convert JSX Fragment to array', () => {
|
|
5
|
-
const view = () => <>
|
|
6
|
-
<li><a></a></li>
|
|
7
|
-
<li><a></a></li>
|
|
8
|
-
</>;
|
|
9
|
-
const vdom = view();
|
|
10
|
-
expect(vdom.length).toBe(2);
|
|
11
|
-
})
|
|
12
|
-
it('should support JSX Fragment keyword to array', () => {
|
|
13
|
-
const view = () => <app.Fragment>
|
|
14
|
-
<li><a></a></li>
|
|
15
|
-
<li><a></a></li>
|
|
16
|
-
</app.Fragment>;
|
|
17
|
-
const vdom = view();
|
|
18
|
-
expect(vdom.length).toBe(2);
|
|
19
|
-
})
|
|
20
|
-
it('should convert merge JSX Fragment to parents', () => {
|
|
21
|
-
const view = () => <ul><>
|
|
22
|
-
<li><a></a></li>
|
|
23
|
-
<li><a></a></li>
|
|
24
|
-
</>
|
|
25
|
-
<li><a></a></li></ul>;
|
|
26
|
-
const vdom = view();
|
|
27
|
-
expect(vdom.tag).toBe('ul');
|
|
28
|
-
expect(vdom.children.length).toBe(3)
|
|
29
|
-
})
|
|
30
|
-
it('should support JSX Fragment at root level with mutiple elements', () => {
|
|
31
|
-
const el = document.createElement('div');
|
|
32
|
-
const view = () => <>
|
|
33
|
-
<li><a></a></li>
|
|
34
|
-
<li><a></a></li>
|
|
35
|
-
</>
|
|
36
|
-
const vdom = view();
|
|
37
|
-
expect(Array.isArray(vdom)).toBeTruthy();
|
|
38
|
-
app.render(el, vdom);
|
|
39
|
-
expect(el.childElementCount).toBe(2);
|
|
40
|
-
})
|
|
41
|
-
it('should support JSX Fragment at root level with signle element', () => {
|
|
42
|
-
const el = document.createElement('div');
|
|
43
|
-
const view = () => <>
|
|
44
|
-
<li><a></a></li>
|
|
45
|
-
</>
|
|
46
|
-
const vdom = view();
|
|
47
|
-
expect(Array.isArray(vdom)).toBeTruthy();
|
|
48
|
-
app.render(el, vdom);
|
|
49
|
-
expect(el.childElementCount).toBe(1);
|
|
50
|
-
expect(el.innerHTML).toBe('<li><a></a></li>');
|
|
51
|
-
})
|
|
52
|
-
it('should remove extra', () => {
|
|
53
|
-
const el = document.createElement('ul');
|
|
54
|
-
el.innerHTML='<li>a</li><li>b</li><li>c</li>'
|
|
55
|
-
const view = () => <><li><a></a></li><li><a></a></li></>
|
|
56
|
-
const vdom = view();
|
|
57
|
-
app.render(el, vdom);
|
|
58
|
-
expect(el.childElementCount).toBe(2);
|
|
59
|
-
expect(el.innerHTML).toBe('<li><a></a></li><li><a></a></li>');
|
|
60
|
-
})
|
|
61
|
-
it('should combine string and tags', () => {
|
|
62
|
-
const el = document.createElement('div');
|
|
63
|
-
el.innerHTML = '<h1><h1>';
|
|
64
|
-
const view = () => <>aaa<div>b</div>{' '}</>
|
|
65
|
-
const vdom = view();
|
|
66
|
-
app.render(el, vdom);
|
|
67
|
-
expect(vdom.length).toBe(3);
|
|
68
|
-
expect(el.innerHTML).toBe('aaa<div>b</div> ');
|
|
69
|
-
})
|
|
70
|
-
it('should combine string and tags', () => {
|
|
71
|
-
const el = document.createElement('div');
|
|
72
|
-
el.innerHTML = '<h1><h1>';
|
|
73
|
-
const view = () => <>{' '} <div>b</div> {' '}</>
|
|
74
|
-
const vdom = view();
|
|
75
|
-
app.render(el, vdom);
|
|
76
|
-
expect(vdom.length).toBe(5);
|
|
77
|
-
expect(el.innerHTML).toBe(' <div>b</div> ');
|
|
78
|
-
})
|
|
79
|
-
})
|