apprun 3.28.8 → 3.28.11

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 (51) hide show
  1. package/CHANGELOG.md +4 -2
  2. package/README.md +8 -40
  3. package/WHATSNEW.md +6 -6
  4. package/apprun-cli.js +3 -221
  5. package/dist/apprun-html.esm.js +3 -3
  6. package/dist/apprun-html.esm.js.map +1 -1
  7. package/dist/apprun-html.js +1 -1
  8. package/dist/apprun-html.js.map +1 -1
  9. package/dist/apprun-play.js +1 -1
  10. package/dist/apprun-play.js.map +1 -1
  11. package/dist/apprun.esm.js +1 -1
  12. package/dist/apprun.esm.js.map +1 -1
  13. package/dist/apprun.js +1 -1
  14. package/dist/apprun.js.map +1 -1
  15. package/esm/component.js +2 -1
  16. package/esm/component.js.map +1 -1
  17. package/esm/directive.js +3 -3
  18. package/esm/directive.js.map +1 -1
  19. package/esm/vdom-lit-html.js +7 -1
  20. package/esm/vdom-lit-html.js.map +1 -1
  21. package/esm/vdom-my.js +9 -3
  22. package/esm/vdom-my.js.map +1 -1
  23. package/esm/vdom.js +1 -4
  24. package/esm/vdom.js.map +1 -1
  25. package/esm/web-component.js +18 -16
  26. package/esm/web-component.js.map +1 -1
  27. package/package.json +9 -11
  28. package/src/component.ts +1 -1
  29. package/src/directive.ts +3 -3
  30. package/src/vdom-lit-html.ts +6 -1
  31. package/src/vdom-my.ts +8 -3
  32. package/src/vdom.ts +1 -4
  33. package/src/web-component.ts +16 -14
  34. package/cli-templates/Layout.ts_ +0 -35
  35. package/cli-templates/_build.js +0 -27
  36. package/cli-templates/_eslintrc.js +0 -40
  37. package/cli-templates/_gitignore +0 -6
  38. package/cli-templates/component.ts_ +0 -14
  39. package/cli-templates/index.html +0 -10
  40. package/cli-templates/jest.config.js +0 -19
  41. package/cli-templates/karma.conf.js +0 -24
  42. package/cli-templates/main.ts_ +0 -13
  43. package/cli-templates/readme.md +0 -7
  44. package/cli-templates/spa_index.html +0 -14
  45. package/cli-templates/spa_main.ts_ +0 -12
  46. package/cli-templates/spec.ts_ +0 -12
  47. package/cli-templates/stories.js_ +0 -47
  48. package/cli-templates/tsconfig.es5.json +0 -15
  49. package/cli-templates/tsconfig.es6.json +0 -15
  50. package/cli-templates/webpack.config.js +0 -24
  51. package/index-apprun-play.html +0 -46
@@ -1 +1 @@
1
- {"version":3,"file":"web-component.js","sourceRoot":"","sources":["../src/web-component.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,UAAgC,EAAE,EAAE,EAAE,CAAC,MAAM,aAAc,SAAQ,WAAW;IAM1H;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IACD,IAAI,SAAS,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7C,MAAM,KAAK,kBAAkB;QAC3B,kEAAkE;QAClE,OAAO,CAAC,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,iBAAiB;QACf,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACxC,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,CAAC;YAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC5E,MAAM,kBAAkB,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAA;YAE1D,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACtD,M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E;oBAChC,kEAAkE;oBAClE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBAC1B,CAAC,CAAC,CAAA;aACH;SACF;IACH,CAAC;CACF,CAAA;AAED,eAAe,CAAC,IAAY,EAAE,cAAc,EAAE,OAA8B,EAAE,EAAE;IAC9E,CAAC,OAAO,cAAc,KAAK,WAAW,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAA;AAChH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "apprun",
3
- "version": "3.28.8",
3
+ "version": "3.28.11",
4
4
  "description": "JavaScript library that has Elm inspired architecture, event pub-sub and components",
5
5
  "main": "dist/apprun.js",
6
6
  "module": "dist/apprun.esm.js",
7
7
  "types": "apprun.d.ts",
8
+ "type": "module",
8
9
  "bin": {
9
10
  "apprun": "apprun-cli.js"
10
11
  },
@@ -37,26 +38,23 @@
37
38
  "url": "https://github.com/yysun/apprun/issues"
38
39
  },
39
40
  "homepage": "https://github.com/yysun/apprun#readme",
40
- "dependencies": {
41
- "commander": "^7.2.0"
42
- },
43
41
  "devDependencies": {
44
- "@rollup/plugin-commonjs": "^21.0.1",
42
+ "@rollup/plugin-commonjs": "^21.0.2",
45
43
  "@rollup/plugin-node-resolve": "^13.1.3",
46
- "@types/jest": "^27.4.0",
44
+ "@types/jest": "^27.4.1",
47
45
  "jest": "^27.5.1",
48
46
  "json-loader": "^0.5.7",
49
- "lit-html": "^2.1.3",
47
+ "lit-html": "^2.2.1",
50
48
  "marked": "^4.0.12",
51
- "rollup": "^2.67.2",
49
+ "rollup": "^2.70.1",
52
50
  "rollup-plugin-filesize": "^9.1.2",
53
51
  "rollup-plugin-node-resolve": "^5.2.0",
54
52
  "rollup-plugin-sourcemaps": "^0.6.3",
55
53
  "rollup-plugin-terser": "^7.0.2",
56
54
  "ts-jest": "^27.1.3",
57
- "ts-loader": "^9.2.6",
58
- "typescript": "^4.5.5",
59
- "webpack": "^5.68.0",
55
+ "ts-loader": "^9.2.8",
56
+ "typescript": "^4.6.2",
57
+ "webpack": "^5.70.0",
60
58
  "webpack-cli": "^4.9.2",
61
59
  "webpack-dev-server": "^4.7.4"
62
60
  },
package/src/component.ts CHANGED
@@ -144,7 +144,7 @@ export class Component<T = any, E = any> {
144
144
 
145
145
  if (options.route) {
146
146
  this.update = this.update || {};
147
- this.update[options.route] = REFRESH;
147
+ if (!this.update[options.route]) this.update[options.route] = REFRESH;
148
148
  }
149
149
 
150
150
  this.add_actions();
package/src/directive.ts CHANGED
@@ -19,15 +19,15 @@ const apply_directive = (key: string, props: {}, tag, component) => {
19
19
  const event = props[key];
20
20
  key = key.substring(1)
21
21
  if (typeof event === 'boolean') {
22
- props[key] = e => component.run(key, e);
22
+ props[key] = e => component.run ? component.run(key, e) : app.run(key, e);
23
23
  } else if (typeof event === 'string') {
24
- props[key] = e => component.run(event, e);
24
+ props[key] = e => component.run ? component.run(event, e) : app.run(event, e);
25
25
  } else if (typeof event === 'function') {
26
26
  props[key] = e => component.setState(event(component.state, e));
27
27
  } else if (Array.isArray(event)) {
28
28
  const [handler, ...p] = event;
29
29
  if (typeof handler === 'string') {
30
- props[key] = e => component.run(handler, ...p, e);
30
+ props[key] = e => component.run ? component.run(handler, ...p, e) : app.run(handler, ...p, e);
31
31
  } else if (typeof handler === 'function') {
32
32
  props[key] = e => component.setState(handler(component.state, ...p, e));
33
33
  }
@@ -4,10 +4,12 @@ import { createElement, updateElement, Fragment } from './vdom-my';
4
4
  import { render, svg, html, noChange, nothing } from 'lit-html';
5
5
  import { directive, Directive, Part, PartInfo, PartType, EventPart } from 'lit-html/directive.js';
6
6
  import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
7
+ import app from './apprun';
7
8
 
8
9
  function _render(element, vdom, parent?) {
9
10
  if (!vdom) return;
10
11
  if (typeof vdom === 'string') {
12
+ if (!element['_$litPart$']) element.replaceChildren();
11
13
  render(html`${unsafeHTML(vdom)}`, element);
12
14
  } else if ('_$litType$' in vdom) {
13
15
  if (!element['_$litPart$']) element.replaceChildren();
@@ -44,7 +46,10 @@ export class RunDirective extends Directive {
44
46
  }
45
47
  const [event, ...args] = params;
46
48
  if (typeof event === 'string') {
47
- element[`on${name}`] = e => getComponent().run(event, ...args, e);
49
+ element[`on${name}`] = e => {
50
+ const component = getComponent();
51
+ component ? component.run(event, ...args, e) : app.run(event, ...args, e)
52
+ }
48
53
  } else if (typeof event === 'function') {
49
54
  element[`on${name}`] = e => getComponent().setState(event(getComponent().state, ...args, e));
50
55
  }
package/src/vdom-my.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { VDOM, VNode } from './types';
2
+ import directive from './directive';
2
3
  export type Element = any; //HTMLElement | SVGSVGElement | SVGElement;
3
4
 
4
5
  export function Fragment(props, ...children): any[] {
@@ -36,10 +37,14 @@ export function createElement(tag: string | Function | [], props?: {}, ...childr
36
37
 
37
38
  const keyCache = new WeakMap();
38
39
 
39
- export const updateElement = render;
40
+ export const updateElement = (element: Element, nodes: VDOM, component = {}) => {
41
+ // tslint:disable-next-line
42
+ if (nodes == null || nodes === false) return;
43
+ nodes = directive(nodes, component);
44
+ render(element, nodes, component);
45
+ }
40
46
 
41
- export function render(element: Element, nodes: VDOM, parent = {}) {
42
- // console.log('render', element, node);
47
+ function render(element: Element, nodes: VDOM, parent = {}) {
43
48
  // tslint:disable-next-line
44
49
  if (nodes == null || nodes === false) return;
45
50
 
package/src/vdom.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  import { createElement, updateElement, Fragment } from './vdom-my';
2
- export function render(element, html, parent?) {
3
- updateElement(element, html, parent);
4
- }
5
- export { createElement, Fragment };
2
+ export { createElement, Fragment, updateElement as render};
6
3
 
7
4
 
@@ -59,20 +59,22 @@ export const customElement = (componentClass, options: CustomElementOptions = {}
59
59
  });
60
60
  })
61
61
 
62
- const children = this.children ? Array.from(this.children) : [];
63
- children.forEach(el => el.parentElement.removeChild(el));
64
- this._component = new componentClass({ ...props, children }).mount(this._shadowRoot, opts);
65
- // attach props to component
66
- this._component._props = props;
67
- // expose dispatchEvent
68
- this._component.dispatchEvent = this.dispatchEvent.bind(this)
69
- if (this._component.mounted) {
70
- const new_state = this._component.mounted(props, children, this._component.state);
71
- if (typeof new_state !== 'undefined') this._component.state = new_state;
72
- }
73
- this.on = this._component.on.bind(this._component);
74
- this.run = this._component.run.bind(this._component);
75
- if (!(opts.render===false)) this._component.run('.');
62
+ requestAnimationFrame(() => {
63
+ const children = this.children ? Array.from(this.children) : [];
64
+ children.forEach(el => el.parentElement.removeChild(el));
65
+ this._component = new componentClass({ ...props, children }).mount(this._shadowRoot, opts);
66
+ // attach props to component
67
+ this._component._props = props;
68
+ // expose dispatchEvent
69
+ this._component.dispatchEvent = this.dispatchEvent.bind(this)
70
+ if (this._component.mounted) {
71
+ const new_state = this._component.mounted(props, children, this._component.state);
72
+ if (typeof new_state !== 'undefined') this._component.state = new_state;
73
+ }
74
+ this.on = this._component.on.bind(this._component);
75
+ this.run = this._component.run.bind(this._component);
76
+ if (!(opts.render === false)) this._component.run('.');
77
+ });
76
78
  }
77
79
  }
78
80
 
@@ -1,35 +0,0 @@
1
-
2
- import app from 'apprun';
3
-
4
- app.on('//', (route) => {
5
- const menus = document.querySelectorAll('.navbar-nav li');
6
- for (let i = 0; i < menus.length; ++i) {menus[i].classList.remove('active');}
7
- const item = document.querySelector(`[href='${route}']`);
8
- item && item.parentElement.classList.add('active');
9
- });
10
-
11
- export default () => <div class="container">
12
- <nav class="navbar navbar-expand-lg navbar-light bg-light">
13
- <a class="navbar-brand" href="#">Project Name</a>
14
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
15
- aria-expanded="false" aria-label="Toggle navigation">
16
- <span class="navbar-toggler-icon"></span>
17
- </button>
18
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
19
- <ul class="navbar-nav mr-auto">
20
- <li class="nav-item active">
21
- <a class="nav-link" href="#Home">Home
22
- <span class="sr-only">(current)</span>
23
- </a>
24
- </li>
25
- <li class="nav-item">
26
- <a class="nav-link" href="#About">About</a>
27
- </li>
28
- <li class="nav-item">
29
- <a class="nav-link" href="#Contact">Contact</a>
30
- </li>
31
- </ul>
32
- </div>
33
- </nav>
34
- <div class="container" id="my-app"></div>
35
- </div>;
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
- const builder = require('esbuild');
3
- const server = require('apprun-dev-server');
4
-
5
- const build = (watch = false) => builder.build({
6
- entryPoints: ['src/main.tsx'],
7
- outfile: 'dist/main.js',
8
- bundle: true,
9
- minify: true,
10
- sourcemap: true,
11
- watch
12
- });
13
-
14
- const start = () => {
15
- server.start({
16
- host: 'localhost',
17
- port: process.env.PORT || 8080,
18
- watch: 'src'
19
- });
20
- }
21
-
22
- if (!process.argv[2]) {
23
- build();
24
- } else {
25
- build(true);
26
- start();
27
- }
@@ -1,40 +0,0 @@
1
- /* eslint-disable no-undef */
2
- module.exports = {
3
- env: {
4
- browser: true,
5
- es2021: true,
6
- },
7
- extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
8
- parser: '@typescript-eslint/parser',
9
- parserOptions: {
10
- ecmaVersion: 12,
11
- sourceType: 'module',
12
- },
13
-
14
- plugins: ['@typescript-eslint'],
15
-
16
- /// https://devstephen.medium.com/style-guides-for-linting-ecmascript-2015-eslint-common-google-airbnb-6c25fd3dff0
17
- rules: {
18
- indent: ['error', 2],
19
- quotes: ['error', 'single'],
20
- semi: ['error', 'always'],
21
- 'no-trailing-spaces': 'error',
22
- 'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0 }],
23
- '@typescript-eslint/explicit-module-boundary-types': 'off',
24
- 'no-case-declarations': 'off',
25
- 'eqeqeq': 'error',
26
- 'curly': ['error', 'all'],
27
- 'brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
28
- 'no-extra-parens': ['error', 'functions'],
29
- 'no-useless-catch': 'error',
30
- 'no-console': 'error',
31
- 'space-before-function-paren': ['error', { 'anonymous': 'always', 'named': 'never', 'asyncArrow': 'always' }],
32
- 'object-curly-spacing': ['error', 'always'],
33
- 'array-bracket-spacing': ['error', 'never'],
34
- 'no-unused-expressions': ['error', { allowShortCircuit: true }],
35
- 'arrow-parens': ['error', 'as-needed', { 'requireForBlockBody': true }],
36
- '@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: 'app' }],
37
- 'no-invalid-this': 'off',
38
- '@typescript-eslint/no-invalid-this': ['error']
39
- },
40
- };
@@ -1,6 +0,0 @@
1
- .DS_Store
2
- Thumbs.db
3
- *.log
4
- node_modules
5
- coverage
6
- .cache
@@ -1,14 +0,0 @@
1
- import { app, Component } from 'apprun';
2
-
3
- export default class #nameComponent extends Component {
4
- state = '#name';
5
-
6
- view = state => <div>
7
- <h1>{state}</h1>
8
- </div>;
9
-
10
- update = {
11
- '##name': state => state,
12
- };
13
- }
14
-
@@ -1,10 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>AppRun App</title>
6
- </head>
7
- <body>
8
- <script type="module" src="./dist/main.js"></script>
9
- </body>
10
- </html>
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- "transform": {
3
- "^.+\\.tsx?$": "ts-jest"
4
- },
5
- "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6
- "moduleFileExtensions": [
7
- "ts",
8
- "tsx",
9
- "js",
10
- "jsx",
11
- "json",
12
- "node"
13
- ],
14
- "globals": {
15
- "ts-jest": {
16
- "diagnostics": true
17
- }
18
- },
19
- }
@@ -1,24 +0,0 @@
1
- var webpackConfig = require('./webpack.config');
2
- module.exports = function (config) {
3
- config.set({
4
- basePath: '',
5
- frameworks: ["jasmine"],
6
- files: [
7
- { pattern: "tests/*.spec.*" }
8
- ],
9
- exclude: [
10
- ],
11
- preprocessors: {
12
- 'tests/*.spec.*': ['webpack'],
13
- },
14
- webpack: webpackConfig,
15
- reporters: ["progress"],
16
- colors: true,
17
- // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
18
- logLevel: config.LOG_INFO,
19
- browsers: ['Chrome'],
20
- mime: {
21
- 'text/x-typescript': ['ts', 'tsx']
22
- }
23
- })
24
- }
@@ -1,13 +0,0 @@
1
- import app from 'apprun';
2
-
3
- const state = 'Hello world - AppRun !';
4
-
5
- const view = (state) => <div>
6
- <h1>{state}</h1>
7
- </div>;
8
-
9
- const update = {
10
-
11
- };
12
-
13
- app.start(document.body, state, view, update);
@@ -1,7 +0,0 @@
1
- ##
2
-
3
- * Use _npm start_ to start the dev server
4
- * Use _npm test_ to run unit tests
5
- * Use _npm run build_ to build for production
6
-
7
- This is an application built with [AppRun](https://github.com/yysun/apprun).
@@ -1,14 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6
- <title>AppRun SPA</title>
7
- <link rel="stylesheet" href="https://unpkg.com/bootstrap@4.4.1/dist/css/bootstrap.min.css">
8
- <script src="https://unpkg.com/jquery@3.4.1/dist/jquery.slim.min.js"></script>
9
- <script src="https://unpkg.com/popper.js@1.16.1/dist/umd/popper.min.js"></script>
10
- <script src="https://unpkg.com/bootstrap@4.4.1/dist/js/bootstrap.min.js"></script>
11
- <body>
12
- <script type="module" src="./dist/main.js"></script>
13
- </body>
14
- </html>
@@ -1,12 +0,0 @@
1
- import app from 'apprun';
2
- import Home from './Home';
3
- import About from './About';
4
- import Contact from './Contact';
5
- import Layout from './Layout';
6
-
7
- app.render(document.body, <Layout />);
8
-
9
- const element = 'my-app';
10
- new Home().start(element);
11
- new About().mount(element);
12
- new Contact().mount(element);
@@ -1,12 +0,0 @@
1
- import app from 'apprun';
2
- import #name from '../src/#name';
3
-
4
- describe('component', () => {
5
- it('should render state upon route event', () => {
6
- const element = document.createElement('div');
7
- const component = new #name().mount(element);
8
- app.run('##name');
9
- expect(element.textContent).toBe('#name');
10
- expect(component.state).toBe('#name');
11
- });
12
- });
@@ -1,47 +0,0 @@
1
- import #name from '../#name';
2
-
3
- export default {
4
- title: '#name',
5
- argTypes: {
6
- event: {
7
- name: 'event',
8
- type: { name: 'string', required: false },
9
- description: 'event',
10
- control: {
11
- type: 'text'
12
- }
13
- },
14
-
15
- route: {
16
- name: 'route',
17
- type: { name: 'string', required: false },
18
- description: 'route',
19
- control: {
20
- type: 'text'
21
- }
22
- }
23
- },
24
- };
25
-
26
- export const #name_Event = ({ event }) => {
27
- const div = document.createElement('div');
28
- const component = new #name().mount(div);
29
- const e = JSON.parse(event);
30
- const [name, ...params] = e;
31
- component.run(name, ...params);
32
- return div;
33
- };
34
- #name_Event.args = {
35
- event: '["."]',
36
- };
37
-
38
- export const #name_Route = ({ route }) => {
39
- const div = document.createElement('div');
40
- new #name().mount(div);
41
- app.route(route);
42
- return div;
43
- };
44
-
45
- #name_Route.args = {
46
- route: '##name',
47
- };
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "module": "es2015",
5
- "moduleResolution": "node",
6
- "jsx": "react",
7
- "jsxFactory": "app.h",
8
- "jsxFragmentFactory": "app.Fragment",
9
- "lib": ["dom", "es2015", "es5"],
10
- "experimentalDecorators": true,
11
- "sourceMap": true,
12
- "esModuleInterop": true,
13
- "outDir": "dist"
14
- }
15
- }
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2015",
4
- "module": "es2015",
5
- "moduleResolution": "node",
6
- "jsx": "react",
7
- "jsxFactory": "app.h",
8
- "jsxFragmentFactory": "app.Fragment",
9
- "lib": ["dom", "es2015", "es5"],
10
- "experimentalDecorators": true,
11
- "sourceMap": true,
12
- "esModuleInterop": true,
13
- "outDir": "dist"
14
- }
15
- }
@@ -1,24 +0,0 @@
1
- const path = require('path');
2
- module.exports = {
3
- entry: {
4
- 'dist/main': './src/main.tsx',
5
- },
6
- output: {
7
- filename: '[name].js',
8
- path: path.resolve(__dirname)
9
- },
10
- resolve: {
11
- extensions: ['.ts', '.tsx', '.js']
12
- },
13
- module: {
14
- rules: [
15
- { test: /\.tsx?$/, loader: 'ts-loader' },
16
- { test: /\.js$/, use: ["source-map-loader"], enforce: "pre" }
17
- ]
18
- },
19
- devServer: {
20
- open: true,
21
- static: path.join(__dirname),
22
- },
23
- devtool: 'source-map'
24
- }
@@ -1,46 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>AppRun Play</title>
6
- <link rel="stylesheet" href="demo/lib/codemirror.css">
7
- <script src="demo/lib/codemirror.js"></script>
8
- <script src="demo/mode/javascript/javascript.js"></script>
9
- <script src="demo/mode/xml/xml.js"></script>
10
- <script src="demo/mode/jsx/jsx.js"></script>
11
- <script src="dist/apprun-play.js"></script>
12
- </head>
13
- <body>
14
- <textarea style="width:100%; height:300px">
15
- const state = 0;
16
- const view = state => {
17
- return `<div>
18
- <h1>${state}</h1>
19
- <button onclick='app.run("-1")'>-1</button>
20
- <button onclick='app.run("+1")'>+1</button>
21
- </div>`;
22
- };
23
- const update = {
24
- '+1': state => state + 1,
25
- '-1': state => state - 1
26
- };
27
- app.start(document.body, state, view, update);
28
- </textarea>
29
- <apprun-play></apprun-play>
30
-
31
- <textarea>
32
- <html>
33
- <body>
34
- <script src="https://unpkg.com/apprun/dist/apprun-html.js"></script>
35
- <script>
36
- const view = state => `<div>${state}</div>`;
37
- app.start(document.body, 'hello world', view);
38
- </script>
39
- </body>
40
- </html>
41
- </textarea>
42
- <p>
43
- <apprun-play></apprun-play>
44
- </p>
45
- </body>
46
- </html>