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.
Files changed (135) hide show
  1. package/CHANGELOG.md +235 -12
  2. package/LICENSE +1 -1
  3. package/README.md +225 -110
  4. package/apprun.d.ts +240 -34
  5. package/cli/app.js +29 -0
  6. package/cli/colors.js +69 -0
  7. package/cli/index.html +13 -0
  8. package/cli/index.js +96 -0
  9. package/dist/apprun-code.js +2 -0
  10. package/dist/apprun-code.js.map +1 -0
  11. package/dist/apprun-dev-tools.js +1 -1
  12. package/dist/apprun-dev-tools.js.map +1 -1
  13. package/dist/apprun-html.esm.js +34 -0
  14. package/dist/apprun-html.esm.js.map +1 -0
  15. package/dist/apprun-html.js +2 -1
  16. package/dist/apprun-html.js.LICENSE.txt +11 -0
  17. package/dist/apprun-html.js.map +1 -1
  18. package/dist/apprun-play.js +2 -0
  19. package/dist/apprun-play.js.map +1 -0
  20. package/dist/apprun.esm.js +2 -0
  21. package/dist/apprun.esm.js.map +1 -0
  22. package/dist/apprun.js +1 -1
  23. package/dist/apprun.js.map +1 -1
  24. package/dist/createState.js +2 -0
  25. package/dist/createState.js.map +1 -0
  26. package/esm/add-components.js +90 -0
  27. package/esm/add-components.js.map +1 -0
  28. package/esm/app.js +209 -0
  29. package/esm/app.js.map +1 -0
  30. package/esm/apprun-code.js +170 -0
  31. package/esm/apprun-code.js.map +1 -0
  32. package/esm/apprun-dev-tools-tests.js +95 -0
  33. package/esm/apprun-dev-tools-tests.js.map +1 -0
  34. package/esm/apprun-dev-tools.js +281 -0
  35. package/esm/apprun-dev-tools.js.map +1 -0
  36. package/esm/apprun-html.js +24 -0
  37. package/esm/apprun-html.js.map +1 -0
  38. package/esm/apprun-play.js +248 -0
  39. package/esm/apprun-play.js.map +1 -0
  40. package/esm/apprun.js +220 -0
  41. package/esm/apprun.js.map +1 -0
  42. package/esm/component.js +413 -0
  43. package/esm/component.js.map +1 -0
  44. package/esm/createState.js +9 -0
  45. package/esm/createState.js.map +1 -0
  46. package/esm/decorator.js +88 -0
  47. package/esm/decorator.js.map +1 -0
  48. package/esm/directive.js +306 -0
  49. package/esm/directive.js.map +1 -0
  50. package/esm/router.js +345 -0
  51. package/esm/router.js.map +1 -0
  52. package/esm/type-utils.js +90 -0
  53. package/esm/type-utils.js.map +1 -0
  54. package/esm/types.js +58 -0
  55. package/esm/types.js.map +1 -0
  56. package/esm/vdom-lit-html.js +65 -0
  57. package/esm/vdom-lit-html.js.map +1 -0
  58. package/esm/vdom-my-prop-attr.js +227 -0
  59. package/esm/vdom-my-prop-attr.js.map +1 -0
  60. package/esm/vdom-my.js +293 -0
  61. package/esm/vdom-my.js.map +1 -0
  62. package/esm/vdom-to-html.js +54 -0
  63. package/esm/vdom-to-html.js.map +1 -0
  64. package/esm/vdom.js +28 -0
  65. package/esm/vdom.js.map +1 -0
  66. package/esm/version.js +15 -0
  67. package/esm/version.js.map +1 -0
  68. package/esm/web-component.js +155 -0
  69. package/esm/web-component.js.map +1 -0
  70. package/jsx-runtime.js +2 -0
  71. package/jsx-runtime.js.map +1 -0
  72. package/package.json +90 -41
  73. package/.travis.yml +0 -10
  74. package/.vscode/launch.json +0 -19
  75. package/BACKERS.md +0 -3
  76. package/apprun-cli.js +0 -177
  77. package/cli-templates/_gitignore +0 -6
  78. package/cli-templates/component.ts_ +0 -16
  79. package/cli-templates/index.html +0 -11
  80. package/cli-templates/karma.conf.js +0 -24
  81. package/cli-templates/main.ts_ +0 -13
  82. package/cli-templates/readme.md +0 -7
  83. package/cli-templates/spa_index.html +0 -14
  84. package/cli-templates/spa_main.ts_ +0 -47
  85. package/cli-templates/spec.ts_ +0 -11
  86. package/cli-templates/tsconfig.json +0 -12
  87. package/cli-templates/webpack.config.js +0 -23
  88. package/demo-html/app.js +0 -2
  89. package/demo-html/app.js.map +0 -1
  90. package/demo-html/counter-c.html +0 -29
  91. package/demo-html/counter-wc-event.html +0 -29
  92. package/demo-html/counter-wc.html +0 -29
  93. package/demo-html/counter.html +0 -26
  94. package/demo-html/index.html +0 -14
  95. package/demo-html/main.tsx +0 -31
  96. package/docs/README.md +0 -326
  97. package/docs/index.html +0 -23
  98. package/index.html +0 -85
  99. package/logo.png +0 -0
  100. package/src/app.ts +0 -69
  101. package/src/apprun-dev-tools.tsx +0 -67
  102. package/src/apprun-html.ts +0 -13
  103. package/src/apprun.ts +0 -53
  104. package/src/component.ts +0 -189
  105. package/src/createComponent.tsx +0 -38
  106. package/src/decorator.ts +0 -36
  107. package/src/router.ts +0 -19
  108. package/src/types.ts +0 -9
  109. package/src/vdom-html.ts +0 -17
  110. package/src/vdom-my.ts +0 -191
  111. package/src/vdom-to-html.tsx +0 -45
  112. package/src/vdom.ts +0 -7
  113. package/src/web-component.ts +0 -29
  114. package/tests/app-rx.spec_ +0 -41
  115. package/tests/app.spec.ts +0 -122
  116. package/tests/application.spec.tsx +0 -23
  117. package/tests/component.spec.tsx +0 -296
  118. package/tests/custom-element.spec.tsx +0 -19
  119. package/tests/data-attr.spec.tsx +0 -42
  120. package/tests/decorator.spec.tsx +0 -104
  121. package/tests/fragment.spec.tsx +0 -79
  122. package/tests/hyperscript.spec.ts +0 -43
  123. package/tests/node-test.js +0 -7
  124. package/tests/router.spec.ts +0 -69
  125. package/tests/stateful-component.spec.tsx +0 -248
  126. package/tests/typed.spec.tsx +0 -63
  127. package/tests/vdom-html.spec.ts +0 -35
  128. package/tests/vdom-jsx.spec.tsx +0 -131
  129. package/tests/vdom-my.spec.tsx +0 -195
  130. package/tests/view-engine.spec.js +0 -59
  131. package/tsconfig.json +0 -11
  132. package/tslint.json +0 -124
  133. package/typescriptreact.json +0 -87
  134. package/viewEngine.js +0 -54
  135. package/webpack.config.js +0 -30
@@ -1,195 +0,0 @@
1
- import { createElement, updateElement } from '../src/vdom-my';
2
-
3
- describe('vdom-my', () => {
4
- let root;
5
- beforeEach(() => {
6
- root = document.createElement('div');
7
- });
8
-
9
- function render(vnode) {
10
- updateElement(root, vnode);
11
- return root.firstChild;
12
- }
13
-
14
- it('should create element', () => {
15
- const element = render(createElement('div', null));
16
- expect(element.nodeName).toEqual('DIV');
17
- expect(element.textContent).toEqual('');
18
- });
19
-
20
- it('should create element with text', () => {
21
- const element = render(createElement('div', null, 'x'));
22
- expect(element.nodeName).toEqual('DIV');
23
- expect(element.textContent).toEqual('x');
24
- });
25
-
26
- it('should create element with number', () => {
27
- const element = render(createElement('div', null, 0));
28
- expect(element.nodeName).toEqual('DIV');
29
- expect(element.textContent).toEqual('0');
30
- });
31
-
32
- it('should create element without text', () => {
33
- const element = render(createElement('div', null, ''));
34
- expect(element.nodeName).toEqual('DIV');
35
- expect(element.textContent).toEqual('');
36
- });
37
-
38
- it('should replace element\'s text', () => {
39
- const element = render(createElement('div', null, 'x'));
40
- expect(element.nodeName).toEqual('DIV');
41
- expect(element.textContent).toEqual('x');
42
- render(createElement('div', null, 'xx'));
43
- expect(element.nodeName).toEqual('DIV');
44
- expect(element.textContent).toEqual('xx');
45
- });
46
-
47
- it('should re-create element', () => {
48
- const element = render(createElement('div', null, 'x'));
49
- expect(element.nodeName).toEqual('DIV');
50
- expect(element.textContent).toEqual('x');
51
- render(createElement('p', null, 'xx'));
52
- expect(element.nodeName).toEqual('DIV');
53
- expect(element.textContent).toEqual('x');
54
- expect(root.firstChild.nodeName).toEqual('P');
55
- expect(root.firstChild.textContent).toEqual('xx');
56
- });
57
-
58
- it('should replace element with text', () => {
59
- let element = render(createElement('div', null,
60
- createElement('div', null, 'x')));
61
- expect(element.nodeName).toEqual('DIV');
62
- expect(element.textContent).toEqual('x');
63
- element = render(createElement('div', null, 'xx'));
64
- expect(root.firstChild.nodeName).toEqual('DIV');
65
- expect(root.firstChild.textContent).toEqual('xx');
66
- expect(root.firstChild.children.length).toEqual(0);
67
- });
68
-
69
- it('it should update className', () => {
70
-
71
- const element = render(createElement('div', { className: 'a' }, 'x'));
72
- expect(element.className).toEqual('a');
73
- render(createElement('div', { className: 'a b' }, 'xx'));
74
- expect(element.className).toEqual('a b');
75
- });
76
-
77
- it('it should reset and apply new style', () => {
78
- let element = render(createElement('div', null, 'x'));
79
- expect(element.nodeName).toEqual('DIV');
80
- expect(element.textContent).toEqual('x');
81
- render(createElement("div", { style: { left: '5px' } }));
82
- expect(element.style.left).toEqual('5px');
83
- render(createElement("div", { style: { top: '50px' } }));
84
- expect(element.style.top).toEqual('50px');
85
- expect(element.style.left).toEqual('');
86
- });
87
-
88
- it('it should reset class and style', () => {
89
- let element = render(createElement('div', {
90
- className: 'a',
91
- style: { left: '5px' }
92
- }, 'x'));
93
- expect(element.nodeName).toEqual('DIV');
94
- expect(element.className).toEqual('a');
95
- expect(element.textContent).toEqual('x');
96
- expect(element.style.left).toEqual('5px');
97
- render(createElement("div", null));
98
- expect(element.style.left).toEqual('');
99
- expect(element.className).toEqual('');
100
- });
101
-
102
- it('it should flatten children', () => {
103
- const nodes = [1, 2, 3].map(i => createElement("li", null, i));
104
- const node = createElement("ul", null, nodes);
105
- expect(node.children.length).toEqual(3);
106
- });
107
-
108
- it('it should render array of nodes', () => {
109
- const element = render(createElement('div', 'a'));
110
- let nodes = {
111
- tag: "div",
112
- props: null,
113
- children: [createElement('div', null, 'x'), createElement('div', null, 'xx')]
114
- };
115
- render(nodes);
116
- expect(element.childNodes[0].textContent).toEqual('x');
117
- expect(element.childNodes[1].textContent).toEqual('xx');
118
- });
119
-
120
- it('it should render array of text', () => {
121
- const element = render(createElement('div', 'a'));
122
- const nodes =
123
- { "tag": "div", "props": null, "children": [{ "tag": "div", "props": null, "children": ["Hello: ", "world"] }] }
124
- for (let i = 0; i < 5; i++){
125
- render(nodes);
126
- expect(element.textContent).toEqual('Hello: world');
127
- }
128
- });
129
-
130
- it('it should reuse element based on key', () => {
131
- const element = render(createElement('div', null, [
132
- createElement('div', {key: 'a'}),
133
- createElement('div', {key: 'b'}),
134
- ]));
135
- element.childNodes[1].k = 'b';
136
- render(createElement('div', null, [
137
- createElement('div', {key: 'b'}, 'x')
138
- ]));
139
-
140
- expect(element.firstChild.textContent).toEqual('x');
141
- expect(element.firstChild.k).toBe('b')
142
- expect(element.childNodes.length).toBe(1)
143
- });
144
-
145
- it('it should retain element based on key', () => {
146
- const element = render(createElement('div', null, [
147
- createElement('div', {key: 'a'}),
148
- createElement('div', {key: 'b'}),
149
- ]));
150
- element.childNodes[0].k = 'a';
151
- element.childNodes[1].k = 'b';
152
- render(createElement('div', null, [
153
- createElement('div', {key: 'b'}, 'x'),
154
- createElement('div', {key: 'a'}, 'xx')
155
- ]));
156
-
157
- expect(element.childNodes[0].textContent).toEqual('x');
158
- expect(element.childNodes[0].k).toBe('b')
159
-
160
- expect(element.childNodes[1].textContent).toEqual('xx');
161
- expect(element.childNodes[1].k).toBe('a')
162
- });
163
-
164
-
165
- it('it should remove element', () => {
166
- const element = render(createElement('div', null,
167
- createElement('input', null),
168
- createElement('input', null),
169
- createElement('input', null)
170
- ));
171
- expect(element.childNodes.length).toBe(3)
172
-
173
- render(createElement('div', null,
174
- createElement('img', null),
175
- null,
176
- createElement('img', null),
177
- ));
178
- expect(element.childNodes.length).toBe(2)
179
- expect(element.outerHTML).toBe('<div><img><img></div>');
180
- });
181
-
182
- it('it should remove text child', () => {
183
- root.innerHTML = "text";
184
- const element = root;
185
-
186
- render(createElement('div', null,
187
- createElement('img', null),
188
- null,
189
- createElement('img', null),
190
- ));
191
- expect(element.childNodes.length).toBe(1)
192
- expect(element.outerHTML).toBe('<div><div><img><img></div></div>');
193
- });
194
-
195
- });
@@ -1,59 +0,0 @@
1
- const toHTML = require('../viewEngine')('html');
2
-
3
- describe('view engine', () => {
4
- it('should not convert vnode to HTML', () => {
5
- const html = toHTML({ tag: 'div', props: null, children: null});
6
- expect(html).toBe('<div></div>')
7
- });
8
-
9
- it('should not convert vnode array to HTML', () => {
10
- const html = toHTML([
11
- { tag: 'div', props: null, children: null },
12
- { tag: 'p', props: null, children: null }
13
- ]);
14
- expect(html).toBe('<div></div><p></p>');
15
- });
16
-
17
- it('should not convert vnode children to HTML', () => {
18
- const html = toHTML({
19
- tag: 'div', props: null, children: [
20
- { tag: 'p', props: null, children: null }]
21
- });
22
- expect(html).toBe('<div><p></p></div>');
23
- });
24
-
25
- it('should not convert vnode props HTML', () => {
26
- const html = toHTML({ tag: 'div', props: {id: 1}, children: null });
27
- expect(html).toBe('<div id="1"></div>')
28
- });
29
-
30
- it('should not convert vnode class HTML', () => {
31
- const html = toHTML({ tag: 'div', props: { className: "1" }, children: null });
32
- expect(html).toBe('<div class="1"></div>')
33
- });
34
-
35
- it('should not convert vnode data attr HTML', () => {
36
- const html = toHTML({ tag: 'div', props: { 'data-a': 'a' }, children: null });
37
- expect(html).toBe('<div data-a="a"></div>')
38
- });
39
-
40
- it('should not convert vnode style props HTML', () => {
41
- const html = toHTML({
42
- tag: 'div',
43
- props: { id: 1, style: { color: 'red' } },
44
- children: null
45
- });
46
- expect(html).toBe('<div id="1" style="color:red"></div>')
47
- });
48
-
49
- it('should not convert vnode style props HTML', () => {
50
- const html = toHTML({
51
- tag: 'div', props: {
52
- id: 1,
53
- style: { color: 'red', 'background-color': 'green' }
54
- },
55
- children: null
56
- });
57
- expect(html).toBe('<div id="1" style="color:red;background-color:green"></div>')
58
- });
59
- })
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2015",
4
- "module": "commonjs",
5
- "jsx": "react",
6
- "reactNamespace": "app",
7
- "lib": ["dom", "es2015", "es5"],
8
- "experimentalDecorators": true,
9
- "sourceMap": true
10
- }
11
- }
package/tslint.json DELETED
@@ -1,124 +0,0 @@
1
- {
2
- "rules": {
3
- // -- Strict errors --
4
- // These lint rules are likely always a good idea.
5
- // Force function overloads to be declared together. This ensures readers understand APIs.
6
- "adjacent-overload-signatures": true,
7
- // Do not allow the subtle/obscure comma operator.
8
- "ban-comma-operator": true,
9
- // Do not allow internal modules or namespaces . These are deprecated in favor of ES6 modules.
10
- "no-namespace": true,
11
- // Do not allow parameters to be reassigned. To avoid bugs, developers should instead assign new values to new vars.
12
- "no-parameter-reassignment": false,
13
- // Force the use of ES6-style imports instead of /// <reference path=> imports.
14
- "no-reference": true,
15
- // Do not allow type assertions that do nothing. This is a big warning that the developer may not understand the
16
- // code currently being edited (they may be incorrectly handling a different type case that does not exist).
17
- "no-unnecessary-type-assertion": true,
18
- // Disallow nonsensical label usage.
19
- "label-position": true,
20
- // Disallows the (often typo) syntax if (var1 = var2). Replace with if (var2) { var1 = var2 }.
21
- "no-conditional-assignment": true,
22
- // Disallows constructors for primitive types (e.g. new Number('123'), though Number('123') is still allowed).
23
- "no-construct": true,
24
- // Do not allow super() to be called twice in a constructor.
25
- "no-duplicate-super": true,
26
- // Do not allow the same case to appear more than once in a switch block.
27
- "no-duplicate-switch-case": true,
28
- // Do not allow a variable to be declared more than once in the same block. Consider function parameters in this
29
- // rule.
30
- "no-duplicate-variable": [
31
- true,
32
- "check-parameters"
33
- ],
34
- // Disallows a variable definition in an inner scope from shadowing a variable in an outer scope. Developers should
35
- // instead use a separate variable name.
36
- "no-shadowed-variable": [false,
37
- {
38
- "class": true,
39
- "enum": true,
40
- "function": true,
41
- "interface": false,
42
- "namespace": true,
43
- "typeAlias": false,
44
- "typeParameter": false
45
- }
46
- ],
47
- // Empty blocks are almost never needed. Allow the one general exception: empty catch blocks.
48
- "no-empty": [
49
- false,
50
- "allow-empty-catch"
51
- ],
52
- // Functions must either be handled directly (e.g. with a catch() handler) or returned to another function.
53
- // This is a major source of errors in Cloud Functions and the team strongly recommends leaving this rule on.
54
- "no-floating-promises": true,
55
- // Do not allow any imports for modules that are not in package.json. These will almost certainly fail when
56
- // deployed.
57
- "no-implicit-dependencies": true,
58
- // The 'this' keyword can only be used inside of classes.
59
- "no-invalid-this": true,
60
- // Do not allow strings to be thrown because they will not include stack traces. Throw Errors instead.
61
- "no-string-throw": true,
62
- // Disallow control flow statements, such as return, continue, break, and throw in finally blocks.
63
- "no-unsafe-finally": true,
64
- // Do not allow variables to be used before they are declared.
65
- "no-use-before-declare": true,
66
- // Expressions must always return a value. Avoids common errors like const myValue = functionReturningVoid();
67
- "no-void-expression": [
68
- true,
69
- "ignore-arrow-function-shorthand"
70
- ],
71
- // Disallow duplicate imports in the same file.
72
- "no-duplicate-imports": true,
73
- // -- Strong Warnings --
74
- // These rules should almost never be needed, but may be included due to legacy code.
75
- // They are left as a warning to avoid frustration with blocked deploys when the developer
76
- // understand the warning and wants to deploy anyway.
77
- // Warn when an empty interface is defined. These are generally not useful.
78
- "no-empty-interface": {
79
- "severity": "warning"
80
- },
81
- // Warn when an import will have side effects.
82
- "no-import-side-effect": {
83
- "severity": "warning"
84
- },
85
- // Warn when variables are defined with var. Var has subtle meaning that can lead to bugs. Strongly prefer const for
86
- // most values and let for values that will change.
87
- "no-var-keyword": {
88
- "severity": "warning"
89
- },
90
- // Prefer === and !== over == and !=. The latter operators support overloads that are often accidental.
91
- "triple-equals": {
92
- "severity": "warning"
93
- },
94
- // Warn when using deprecated APIs.
95
- "deprecation": {
96
- "severity": "warning"
97
- },
98
- // -- Light Warnigns --
99
- // These rules are intended to help developers use better style. Simpler code has fewer bugs. These would be "info"
100
- // if TSLint supported such a level.
101
- // prefer for( ... of ... ) to an index loop when the index is only used to fetch an object from an array.
102
- // (Even better: check out utils like .map if transforming an array!)
103
- "prefer-for-of": {
104
- "severity": "warning"
105
- },
106
- // Warns if function overloads could be unified into a single function with optional or rest parameters.
107
- "unified-signatures": {
108
- "severity": "warning"
109
- },
110
- // Warns if code has an import or variable that is unused.
111
- "no-unused-variable": {
112
- "severity": "warning"
113
- },
114
- // Prefer const for values that will not change. This better documents code.
115
- "prefer-const": {
116
- "severity": "warning"
117
- },
118
- // Multi-line object liiterals and function calls should have a trailing comma. This helps avoid merge conflicts.
119
- "trailing-comma": {
120
- "severity": "warning"
121
- }
122
- },
123
- "defaultSeverity": "error"
124
- }
@@ -1,87 +0,0 @@
1
- {
2
- "AppRun Application": {
3
- "prefix": "apprun",
4
- "body": [
5
- "import app from 'apprun';",
6
- "",
7
- "const state = {}",
8
- "",
9
- "const view = (state) => {",
10
- "\treturn <div>",
11
- "\t\t{state}",
12
- "\t</div>",
13
- "}",
14
- "",
15
- "const update = {",
16
- "\t'#': (state) => state",
17
- "}",
18
- "",
19
- "app.start('${0:my-app}', state, view, update);"
20
- ],
21
- "description": "AppRun application"
22
- },
23
- "AppRun Component": {
24
- "prefix": "component",
25
- "body": [
26
- "import { app, Component } from 'apprun';",
27
- "",
28
- "export default class extends Component {",
29
- "\tstate = {}",
30
- "",
31
- "\tview = (state) => {",
32
- "\t\treturn <div>",
33
- "\t\t\t{state}",
34
- "\t\t</div>",
35
- "\t}",
36
- "",
37
- "\tupdate = {",
38
- "\t\t'#': (state) => state",
39
- "\t}",
40
- "}"
41
- ],
42
- "description": "AppRun application"
43
- },
44
- "AppRun Pure Function Component": {
45
- "prefix": "pfc",
46
- "body": [
47
- "const ${1:Name} = ({ ${2:prop} }) => {",
48
- "\treturn <div>",
49
- "\t\t$0",
50
- "\t</div>",
51
- "}"
52
- ],
53
- "description": "AppRun view function"
54
- },
55
- "AppRun Update": {
56
- "prefix": "@on",
57
- "body": [
58
- "@on() ${1:name} = (state, ${2:e}) => {",
59
- "\treturn { ...state, $2 }",
60
- "}"
61
- ],
62
- "description": "AppRun update function"
63
- },
64
- "AppRun Log State": {
65
- "prefix": "log",
66
- "body": [
67
- "console.log(${1:state})"
68
- ],
69
- "description": "Log state"
70
- },
71
- "AppRun Event Publication": {
72
- "prefix": "run",
73
- "body": [
74
- "{e => ${1|this,app|}.run('$2', e)}"
75
- ],
76
- "description": "AppRun publish event"
77
- },
78
- "AppRun Event Subscription": {
79
- "prefix": "on",
80
- "body": [
81
- "app.on('$1', ($2) => {",
82
- "\t$3",
83
- "})"
84
- ],
85
- "description": "AppRun subscribe to event"
86
- }
87
- }
package/viewEngine.js DELETED
@@ -1,54 +0,0 @@
1
- function getProp(prop) {
2
- if (typeof prop === 'object') {
3
- return Object.keys(prop).map(name => `${name}:${prop[name]}`).join(';');
4
- }
5
- else return prop.toString();
6
- }
7
-
8
- function toProps(props) {
9
- return Object.keys(props)
10
- .map(name => ` ${name === 'className' ? 'class' : name}="${getProp(props[name])}"`)
11
- .join('');
12
- }
13
-
14
- function toHTML(vdom) {
15
- if (!vdom) return '';
16
- if (Array.isArray(vdom)) return toHTMLArray(vdom)
17
- if (vdom.tag) {
18
- const props = vdom.props ? toProps(vdom.props) : '';
19
- const children = vdom.children ? toHTMLArray(vdom.children) : '';
20
- return `<${vdom.tag}${props}>${children}</${vdom.tag}>`;
21
- }
22
- if (typeof vdom === 'object') return JSON.stringify(vdom);
23
- else {
24
- const html = vdom.toString();
25
- return html.startsWith('_html:') ? html.substring(6) : html;
26
- }
27
- }
28
-
29
- function toHTMLArray(nodes) {
30
- return nodes.map(node => toHTML(node)).join('');
31
- }
32
-
33
- function clean(obj) {
34
- for (var i in obj) {
35
- if (obj[i] == null) {
36
- delete obj[i];
37
- } else if (typeof obj[i] === 'object') {
38
- clean(obj[i]);
39
- }
40
- }
41
- }
42
-
43
- function engine(name, options, callback) {
44
- const fn = require(name).default;
45
- const rendered = fn(options);
46
- clean(rendered);
47
- return options.ssr ?
48
- callback(null, toHTML(rendered)) :
49
- callback(null, rendered);
50
- }
51
-
52
- module.exports = function (mode) {
53
- return mode === 'html' ? toHTML : engine
54
- }
package/webpack.config.js DELETED
@@ -1,30 +0,0 @@
1
- const path = require('path');
2
-
3
- module.exports = {
4
- entry: {
5
- 'dist/apprun': './src/apprun.ts',
6
- 'dist/apprun-html': './src/apprun-html.ts',
7
- 'dist/apprun-dev-tools': './src/apprun-dev-tools.tsx',
8
- 'demo/app': './demo/main.ts',
9
- 'demo-html/app': './demo-html/main.tsx'
10
- },
11
- output: {
12
- filename: '[name].js',
13
- library: 'apprun',
14
- libraryTarget: 'umd',
15
- path: path.resolve(__dirname),
16
- globalObject: 'this'
17
- },
18
- resolve: {
19
- extensions: ['.ts', '.tsx', '.js']
20
- },
21
- module: {
22
- rules: [
23
- { test: /\.tsx?$/, loader: 'ts-loader' }
24
- ]
25
- },
26
- devServer: {
27
- open: true
28
- },
29
- devtool: 'source-map'
30
- }