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
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import app from '../src/apprun';
|
|
2
|
-
const h = app.createElement;
|
|
3
|
-
import { VNode } from '../src/types';
|
|
4
|
-
|
|
5
|
-
describe('hyperscript', () => {
|
|
6
|
-
it('should be supported case 1', () => {
|
|
7
|
-
const view = state => h('div', null, '1');
|
|
8
|
-
app.start('my-app', 0, view, {});
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('should be supported case 2', () => {
|
|
12
|
-
const view = state => h('div', null,
|
|
13
|
-
h('div', null, '2'),
|
|
14
|
-
h('div', null, '3'));
|
|
15
|
-
const vdom = view({}) as VNode;
|
|
16
|
-
expect(vdom.children.length).toBe(2);
|
|
17
|
-
app.start('my-app', 0, view, {});
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should be supported case 3', () => {
|
|
21
|
-
const view = state => h('div', null, [
|
|
22
|
-
h('div', null, '2'),
|
|
23
|
-
h('div', null, '3')]
|
|
24
|
-
);
|
|
25
|
-
const vdom = view({}) as VNode;
|
|
26
|
-
expect(vdom.children.length).toBe(2);
|
|
27
|
-
app.start('my-app', 0, view, {});
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should be supported case 4', () => {
|
|
31
|
-
const view = state => h('div', null,
|
|
32
|
-
h('div', null,
|
|
33
|
-
h('div', null, '3')
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
const vdom = view({}) as VNode;
|
|
37
|
-
expect(vdom.children.length).toBe(1);
|
|
38
|
-
expect((vdom.children[0] as VNode).children.length).toBe(1);
|
|
39
|
-
app.start('my-app', 0, view, {});
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
|
package/tests/node-test.js
DELETED
package/tests/router.spec.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import app from '../src/apprun';
|
|
2
|
-
import route from '../src/router';
|
|
3
|
-
|
|
4
|
-
describe('router', () => {
|
|
5
|
-
|
|
6
|
-
beforeAll(() => {
|
|
7
|
-
window.onpopstate = () => route(location.hash || location.pathname);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should not fire event if not initialize', () => {
|
|
11
|
-
const fn = jasmine.createSpy('fn');
|
|
12
|
-
app.on('//', fn);
|
|
13
|
-
expect(fn).not.toHaveBeenCalled();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should fire events if initialized', () => {
|
|
17
|
-
const fn1 = jasmine.createSpy('fn1');
|
|
18
|
-
const fn2 = jasmine.createSpy('fn2');
|
|
19
|
-
app.on('#', fn1);
|
|
20
|
-
app.on('//', fn2);
|
|
21
|
-
route('');
|
|
22
|
-
expect(fn1).toHaveBeenCalledWith();
|
|
23
|
-
expect(fn2).toHaveBeenCalledWith('#');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should fire events if location hash changes', (done) => {
|
|
27
|
-
const fn3 = jasmine.createSpy('fn3');
|
|
28
|
-
const fn4 = jasmine.createSpy('fn4');
|
|
29
|
-
app.on('#x', fn3);
|
|
30
|
-
app.on('//', fn4);
|
|
31
|
-
document.location.href = '#x';
|
|
32
|
-
setTimeout(() => {
|
|
33
|
-
expect(fn3).toHaveBeenCalledWith();
|
|
34
|
-
expect(fn4).toHaveBeenCalledWith('#x');
|
|
35
|
-
done();
|
|
36
|
-
}, 100);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should route location path', () => {
|
|
40
|
-
const fn1 = jasmine.createSpy('fn1');
|
|
41
|
-
const fn2 = jasmine.createSpy('fn2');
|
|
42
|
-
app.on('/home', fn1);
|
|
43
|
-
app.on('//', fn2);
|
|
44
|
-
app.run('route', '/home');
|
|
45
|
-
expect(fn1).toHaveBeenCalledWith();
|
|
46
|
-
expect(fn2).toHaveBeenCalledWith('/home');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should route location all path', () => {
|
|
50
|
-
const fn1 = jasmine.createSpy('fn1');
|
|
51
|
-
const fn2 = jasmine.createSpy('fn2');
|
|
52
|
-
app.on('/x', fn1);
|
|
53
|
-
app.on('//', fn2);
|
|
54
|
-
app.run('route', '/x/y/z');
|
|
55
|
-
expect(fn1).toHaveBeenCalledWith('y', 'z');
|
|
56
|
-
expect(fn2).toHaveBeenCalledWith('/x', 'y', 'z');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should not convert / to #', () => {
|
|
60
|
-
const fn1 = jasmine.createSpy('fn1');
|
|
61
|
-
const fn2 = jasmine.createSpy('fn2');
|
|
62
|
-
app.on('#', fn1);
|
|
63
|
-
app.on('/', fn2);
|
|
64
|
-
app.run('route', '/');
|
|
65
|
-
expect(fn1).not.toHaveBeenCalled();
|
|
66
|
-
expect(fn2).toHaveBeenCalled();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
});
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import app, { Component } from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
describe('Stateful Component', () => {
|
|
4
|
-
|
|
5
|
-
it('should pass props to the constructor', () => {
|
|
6
|
-
class Child extends Component {
|
|
7
|
-
view = (state) => {
|
|
8
|
-
return <div>{state}</div>
|
|
9
|
-
}
|
|
10
|
-
constructor({ n }) {
|
|
11
|
-
super();
|
|
12
|
-
expect(n).toBe('7');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class Main extends Component {
|
|
16
|
-
view = (state) => {
|
|
17
|
-
return <div>
|
|
18
|
-
<Child n='7' />
|
|
19
|
-
</div>
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
new Main().start();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should set props as state', () => {
|
|
26
|
-
class Child extends Component {
|
|
27
|
-
view = (state) => {
|
|
28
|
-
expect(state.n).toBe('8');
|
|
29
|
-
return <div>{state.n}</div>
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
class Main extends Component {
|
|
33
|
-
view = (state) => {
|
|
34
|
-
return <div>
|
|
35
|
-
<Child n='8'/>
|
|
36
|
-
</div>
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
new Main().start();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should render children', () => {
|
|
43
|
-
class Child extends Component {
|
|
44
|
-
view = (state) => <div>
|
|
45
|
-
{state.children}
|
|
46
|
-
</div>
|
|
47
|
-
}
|
|
48
|
-
class Main extends Component {
|
|
49
|
-
view = (state) => {
|
|
50
|
-
return <div>
|
|
51
|
-
<Child>
|
|
52
|
-
<p>child</p>
|
|
53
|
-
</Child>
|
|
54
|
-
</div>
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const element = document.createElement('div');
|
|
58
|
-
app.render(element, <Main />);
|
|
59
|
-
expect(element.textContent).toBe('child');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should call mounted function when created', (done) => {
|
|
63
|
-
class Child extends Component {
|
|
64
|
-
view = (state) => {
|
|
65
|
-
return <div>{state.n}</div>
|
|
66
|
-
}
|
|
67
|
-
mounted = (props) => {
|
|
68
|
-
expect(props.n).toBe(0);
|
|
69
|
-
done()
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
class Main extends Component {
|
|
73
|
-
state = 0
|
|
74
|
-
view = (state) => {
|
|
75
|
-
return <div>
|
|
76
|
-
<Child n={0}/>
|
|
77
|
-
</div>
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
new Main().start();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should call rendered function when created', (done) => {
|
|
84
|
-
class Child extends Component {
|
|
85
|
-
view = (state) => {
|
|
86
|
-
return <div>{state.n}</div>
|
|
87
|
-
}
|
|
88
|
-
rendered = (state) => {
|
|
89
|
-
expect(state.n).toBe(0);
|
|
90
|
-
done()
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
class Main extends Component {
|
|
94
|
-
state = 0
|
|
95
|
-
view = (state) => {
|
|
96
|
-
return <div>
|
|
97
|
-
<Child n={0} />
|
|
98
|
-
</div>
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const element = document.createElement('div');
|
|
102
|
-
app.render(element, <Main />);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should call mounted function when refreshed', (done) => {
|
|
106
|
-
class Child extends Component {
|
|
107
|
-
view = (state) => {
|
|
108
|
-
return <div>{state.n}</div>
|
|
109
|
-
}
|
|
110
|
-
mounted = (props) => {
|
|
111
|
-
if (props.n === 1) done();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
class Main extends Component {
|
|
115
|
-
state = 0
|
|
116
|
-
view = (state) => {
|
|
117
|
-
return <div>
|
|
118
|
-
<Child n={state}/>
|
|
119
|
-
</div>
|
|
120
|
-
}
|
|
121
|
-
update = {
|
|
122
|
-
'+1': state => state + 1
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const component = new Main().start();
|
|
126
|
-
component.run('+1');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should allow async event inside the mounted function', (done) => {
|
|
130
|
-
class Child3 extends Component {
|
|
131
|
-
view = (state) => {
|
|
132
|
-
return <div>{state.n}</div>
|
|
133
|
-
}
|
|
134
|
-
mounted = (n) => {
|
|
135
|
-
if (n !== this.state) this.run('init-async', n);
|
|
136
|
-
}
|
|
137
|
-
update = {
|
|
138
|
-
'init-async': async (state, value) =>
|
|
139
|
-
new Promise(resolve =>
|
|
140
|
-
setTimeout(() =>
|
|
141
|
-
resolve(value))
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
class Main extends Component {
|
|
147
|
-
view = (state) => {
|
|
148
|
-
return <div>
|
|
149
|
-
<Child3 n='a' />
|
|
150
|
-
</div>
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const element = document.createElement('div');
|
|
155
|
-
document.body.appendChild(element);
|
|
156
|
-
app.render(element, <Main />);
|
|
157
|
-
setTimeout(() => {
|
|
158
|
-
expect(element.textContent).toEqual('a');
|
|
159
|
-
done();
|
|
160
|
-
},10)
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should off all events after unmount', () => {
|
|
164
|
-
class Ch extends Component {
|
|
165
|
-
update = {
|
|
166
|
-
'#1': state=> state,
|
|
167
|
-
'#2': state => state,
|
|
168
|
-
'1': state=> state,
|
|
169
|
-
'2': state=> state,
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const component = new Ch().mount();
|
|
174
|
-
expect(app['_events']['#1'].length).toBe(1);
|
|
175
|
-
expect(app['_events']['#2'].length).toBe(1);
|
|
176
|
-
expect(component['_app']['_events']['1'].length).toBe(1);
|
|
177
|
-
expect(component['_app']['_events']['2'].length).toBe(1);
|
|
178
|
-
component.unmount();
|
|
179
|
-
expect(app['_events']['#1']).toBeUndefined();
|
|
180
|
-
expect(app['_events']['#2']).toBeUndefined();
|
|
181
|
-
expect(component['_app']['_events']['1']).toBeUndefined();
|
|
182
|
-
expect(component['_app']['_events']['2']).toBeUndefined();
|
|
183
|
-
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should share same instance when refresh', (done) => {
|
|
187
|
-
class Child extends Component {
|
|
188
|
-
state = { n: 0 }
|
|
189
|
-
view = (state) => {
|
|
190
|
-
return <div>{state.n}</div>
|
|
191
|
-
}
|
|
192
|
-
mounted = ({ n }) => {
|
|
193
|
-
// on second refresh, the state should retain
|
|
194
|
-
if (n === 2 && this.state.n === 1) done();
|
|
195
|
-
this.state.n = n;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
class Main extends Component {
|
|
199
|
-
state = 0
|
|
200
|
-
view = (state) => {
|
|
201
|
-
return <div>
|
|
202
|
-
<Child n={state}/>
|
|
203
|
-
</div>
|
|
204
|
-
}
|
|
205
|
-
update = {
|
|
206
|
-
'+1': state => state + 1
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const element = document.createElement('div');
|
|
210
|
-
const component = new Main().start(element);
|
|
211
|
-
|
|
212
|
-
component.run('+1'); // triger a refresh
|
|
213
|
-
component.run('+1'); // triger a refresh
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('should not share the same instance', () => {
|
|
217
|
-
class Child extends Component {
|
|
218
|
-
state = { n: 0 }
|
|
219
|
-
view = (state) => {
|
|
220
|
-
return <div>{state.n}</div>
|
|
221
|
-
}
|
|
222
|
-
constructor({n}) {
|
|
223
|
-
super();
|
|
224
|
-
this.state.n = n;
|
|
225
|
-
}
|
|
226
|
-
// mounted = ({ n }) => { this.setState({n}) }
|
|
227
|
-
}
|
|
228
|
-
class Main extends Component {
|
|
229
|
-
state = 0
|
|
230
|
-
view = (state) => {
|
|
231
|
-
return <div>
|
|
232
|
-
<Child n="1" />
|
|
233
|
-
<div>
|
|
234
|
-
<Child n="2"/>
|
|
235
|
-
</div>
|
|
236
|
-
<Child n="3"/>
|
|
237
|
-
</div>
|
|
238
|
-
}
|
|
239
|
-
update = {
|
|
240
|
-
'+1': state => state + 1
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const element = document.createElement('div');
|
|
244
|
-
app.render(element, <Main />);
|
|
245
|
-
expect(element.textContent).toBe("123");
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
});
|
package/tests/typed.spec.tsx
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import app, { View, Action, Update, Component, StatelessComponent, on, update } from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const element = document.createElement('div');
|
|
5
|
-
|
|
6
|
-
const state = { msg: 'Hello' };
|
|
7
|
-
type State = typeof state;
|
|
8
|
-
|
|
9
|
-
describe('app', () => {
|
|
10
|
-
it('should support global typed application', () => {
|
|
11
|
-
|
|
12
|
-
const view: View<State> = (state) => <div>
|
|
13
|
-
<h1>{state.msg}</h1>
|
|
14
|
-
</div>;
|
|
15
|
-
|
|
16
|
-
const update: Update<State> = {
|
|
17
|
-
'#': (state) => state,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
app.start<State>(element, state, view, update);
|
|
21
|
-
expect(element.textContent).toBe('Hello');
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should support typed component', () => {
|
|
26
|
-
class MyComponent extends Component<State> {
|
|
27
|
-
|
|
28
|
-
state = { msg: 'World' };
|
|
29
|
-
|
|
30
|
-
view: View<State> = state => <h1>{state.msg}</h1>;
|
|
31
|
-
|
|
32
|
-
update = {
|
|
33
|
-
'#1': state => state,
|
|
34
|
-
'#2': (state: State) => state,
|
|
35
|
-
'#3': async (state: State) => state
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@on('#4')
|
|
39
|
-
route: Action<State> = (state) => state
|
|
40
|
-
|
|
41
|
-
@update('#5')
|
|
42
|
-
route1(state) {
|
|
43
|
-
return state;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
new MyComponent().start(element);
|
|
48
|
-
expect(element.textContent).toBe('World');
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should support typed stateless component', () => {
|
|
53
|
-
const a = { msg: 'Hello' };
|
|
54
|
-
const List1: StatelessComponent<typeof a> = (a) => <div>{a.msg}</div>;
|
|
55
|
-
const List2: StatelessComponent<typeof a> = (a) => '';
|
|
56
|
-
const List3: StatelessComponent<typeof a> = (a) => { };
|
|
57
|
-
|
|
58
|
-
expect(List1(a)).toEqual({ tag: 'div', props: null, children: ['Hello'] });
|
|
59
|
-
expect(List2(a)).toBe('');
|
|
60
|
-
expect(List3(a)).toBe(undefined);
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
})
|
package/tests/vdom-html.spec.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import app from '../src/apprun-html';
|
|
2
|
-
|
|
3
|
-
const model = 'y';
|
|
4
|
-
const view = _ => `\n <div>${_}</div>`;
|
|
5
|
-
const update = {
|
|
6
|
-
hi: (_, val) => val
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe('vdom-html', () => {
|
|
10
|
-
|
|
11
|
-
let element;
|
|
12
|
-
beforeEach(()=>{
|
|
13
|
-
element = document.createElement('div');
|
|
14
|
-
app.start(element, model, view, update);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should create first child element', () => {
|
|
18
|
-
expect(element.firstChild.nodeName).toEqual('DIV');
|
|
19
|
-
expect(element.firstChild.textContent).toEqual('y');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should re-create child element', () => {
|
|
23
|
-
element.removeChild(element.firstChild);
|
|
24
|
-
app.run('hi', 'yy');
|
|
25
|
-
expect(element.firstChild.nodeName).toEqual('DIV');
|
|
26
|
-
expect(element.firstChild.textContent).toEqual('yy');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should update child element', () => {
|
|
30
|
-
app.run('hi', 'yyy');
|
|
31
|
-
expect(element.firstChild.nodeName).toEqual('DIV');
|
|
32
|
-
expect(element.firstChild.textContent).toEqual('yyy');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
});
|
package/tests/vdom-jsx.spec.tsx
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import app, { Component } from '../src/apprun';
|
|
2
|
-
|
|
3
|
-
const model = 'x';
|
|
4
|
-
const view = _ => <div>{_}</div>;
|
|
5
|
-
const update = {
|
|
6
|
-
hi: (_, val) => val
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class TestComponent extends Component {
|
|
10
|
-
state = 'x';
|
|
11
|
-
view = (state) => <div>{state}</div>
|
|
12
|
-
update = {
|
|
13
|
-
'#hi': (state, v) => v
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('vdom-jsx', () => {
|
|
18
|
-
|
|
19
|
-
let element;
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
element = document.createElement('div');
|
|
22
|
-
app.start(element, model, view, update);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('created by app.start should trigger view', () => {
|
|
26
|
-
const model = 'x';
|
|
27
|
-
const view = jasmine.createSpy('view');
|
|
28
|
-
const component = app.start(document.body, model, view, update);
|
|
29
|
-
expect(view).toHaveBeenCalledWith('x');
|
|
30
|
-
app.run('hi', 'xx');
|
|
31
|
-
expect(view).toHaveBeenCalledWith('xx');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should create first child element', () => {
|
|
35
|
-
expect(element.firstChild.nodeName).toEqual('DIV');
|
|
36
|
-
expect(element.firstChild.textContent).toEqual('x');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should re-create child element', () => {
|
|
40
|
-
element.removeChild(element.firstChild);
|
|
41
|
-
app.run('hi', 'xx');
|
|
42
|
-
expect(element.firstChild.nodeName).toEqual('DIV');
|
|
43
|
-
expect(element.firstChild.textContent).toEqual('xx');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should update child element', () => {
|
|
47
|
-
app.run('hi', 'xxx');
|
|
48
|
-
expect(element.firstChild.nodeName).toEqual('DIV');
|
|
49
|
-
expect(element.firstChild.textContent).toEqual('xxx');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should render custom element', () => {
|
|
53
|
-
const CustomElement = ({ val }) => <div>{val}</div>;
|
|
54
|
-
const view = _ => <CustomElement val={_} />;
|
|
55
|
-
const element = document.createElement('div');
|
|
56
|
-
document.body.appendChild(element);
|
|
57
|
-
app.start(element, model, view, update);
|
|
58
|
-
app.run('hi', 'xxxxx');
|
|
59
|
-
expect(element.firstChild.textContent).toEqual('xxxxx');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should render nested element', () => {
|
|
63
|
-
const CustomElement = ({ val }) => <li>{val}</li>;
|
|
64
|
-
const view = _ => (
|
|
65
|
-
<ul>
|
|
66
|
-
<CustomElement val={_ + '1'} />
|
|
67
|
-
<CustomElement val={_ + '2'} />
|
|
68
|
-
<CustomElement val={_ + '3'} />
|
|
69
|
-
<CustomElement val={_ + '4'} />
|
|
70
|
-
</ul>);
|
|
71
|
-
const element = document.createElement('div');
|
|
72
|
-
document.body.appendChild(element);
|
|
73
|
-
app.start(element, '', view, update);
|
|
74
|
-
const el = element.firstChild as HTMLElement;
|
|
75
|
-
|
|
76
|
-
expect(el.children[0].textContent).toEqual('1');
|
|
77
|
-
expect(el.children[1].textContent).toEqual('2');
|
|
78
|
-
expect(el.children[2].textContent).toEqual('3');
|
|
79
|
-
expect(el.children[3].textContent).toEqual('4');
|
|
80
|
-
|
|
81
|
-
app.run('hi', 'x');
|
|
82
|
-
expect(el.children[0].textContent).toEqual('x1');
|
|
83
|
-
expect(el.children[1].textContent).toEqual('x2');
|
|
84
|
-
expect(el.children[2].textContent).toEqual('x3');
|
|
85
|
-
expect(el.children[3].textContent).toEqual('x4');
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should render JSON', () => {
|
|
90
|
-
const view = _ => <div>{_}</div>;
|
|
91
|
-
const element = document.createElement('div');
|
|
92
|
-
document.body.appendChild(element);
|
|
93
|
-
app.start(element, { name: 'x' }, view, update);
|
|
94
|
-
expect(element.textContent).toEqual('{"name":"x"}');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should allow element to be string', () => {
|
|
98
|
-
const element = document.createElement('div');
|
|
99
|
-
element.id = 'main';
|
|
100
|
-
document.body.appendChild(element);
|
|
101
|
-
new TestComponent().start('main');
|
|
102
|
-
expect(element.textContent).toEqual('x');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should render stateful component with id', () => {
|
|
106
|
-
class TestComponent2 extends Component {
|
|
107
|
-
view = (state) => {
|
|
108
|
-
return <div>
|
|
109
|
-
<TestComponent id='test' />
|
|
110
|
-
</div>
|
|
111
|
-
}
|
|
112
|
-
update = {
|
|
113
|
-
'#hi2': (state, v) => {
|
|
114
|
-
const c = document.getElementById('test')['_component'];
|
|
115
|
-
c.run('#hi', v);
|
|
116
|
-
return state;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const element = document.createElement('div');
|
|
122
|
-
document.body.appendChild(element);
|
|
123
|
-
new TestComponent2().start(element);
|
|
124
|
-
expect(element.textContent).toEqual('x');
|
|
125
|
-
app.run('#hi', 'xxxx');
|
|
126
|
-
expect(element.textContent).toEqual('xxxx');
|
|
127
|
-
app.run('#hi2', 'xxxxx');
|
|
128
|
-
expect(element.textContent).toEqual('xxxxx');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
})
|