apprun 3.33.6 → 3.33.8

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/src/apprun.ts CHANGED
@@ -6,6 +6,13 @@ import { on, update, customElement } from './decorator';
6
6
  import webComponent, { CustomElementOptions } from './web-component';
7
7
  import { Route, route, ROUTER_EVENT, ROUTER_404_EVENT } from './router';
8
8
 
9
+ export type StatelessComponent<T = {}> = (args: T) => string | VNode | void;
10
+ export { App, app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment, safeHTML }
11
+ export { update as event };
12
+ export { ROUTER_EVENT, ROUTER_404_EVENT };
13
+ export { customElement, CustomElementOptions, AppStartOptions };
14
+ export default app as IApp;
15
+
9
16
  export interface IApp {
10
17
  start<T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
11
18
  options?: AppStartOptions<T>): Component<T, E>;
@@ -24,68 +31,64 @@ export interface IApp {
24
31
  use_react(createRoot);
25
32
  }
26
33
 
27
- app.h = app.createElement = createElement;
28
- app.render = render;
29
- app.Fragment = Fragment;
30
- app.webComponent = webComponent;
31
- app.safeHTML = safeHTML;
34
+ if (!app.start) {
35
+ app.h = app.createElement = createElement;
36
+ app.render = render;
37
+ app.Fragment = Fragment;
38
+ app.webComponent = webComponent;
39
+ app.safeHTML = safeHTML;
32
40
 
33
- app.start = <T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
34
- options?: AppStartOptions<T>): Component<T, E> => {
35
- const opts = { render: true, global_event: true, ...options };
36
- const component = new Component<T, E>(model, view, update);
37
- if (options && options.rendered) component.rendered = options.rendered;
38
- if (options && options.mounted) component.mounted = options.mounted;
39
- component.start(element, opts);
40
- return component;
41
- };
41
+ app.start = <T, E = any>(element?: Element | string, model?: T, view?: View<T>, update?: Update<T, E>,
42
+ options?: AppStartOptions<T>): Component<T, E> => {
43
+ const opts = { render: true, global_event: true, ...options };
44
+ const component = new Component<T, E>(model, view, update);
45
+ if (options && options.rendered) component.rendered = options.rendered;
46
+ if (options && options.mounted) component.mounted = options.mounted;
47
+ component.start(element, opts);
48
+ return component;
49
+ };
42
50
 
43
- const NOOP = _ => {/* Intentionally empty */ }
44
- app.on('$', NOOP);
45
- app.on('debug', _ => NOOP);
46
- app.on(ROUTER_EVENT, NOOP);
47
- app.on('#', NOOP);
48
- app['route'] = route;
49
- app.on('route', url => app['route'] && app['route'](url));
51
+ const NOOP = _ => {/* Intentionally empty */ }
52
+ app.on('$', NOOP);
53
+ app.on('debug', _ => NOOP);
54
+ app.on(ROUTER_EVENT, NOOP);
55
+ app.on('#', NOOP);
56
+ app['route'] = route;
57
+ app.on('route', url => app['route'] && app['route'](url));
50
58
 
51
- if (typeof document === 'object') {
52
- document.addEventListener("DOMContentLoaded", () => {
53
- if (app['route'] === route) {
54
- window.onpopstate = () => route(location.hash);
55
- document.body.hasAttribute('apprun-no-init') || app['no-init-route'] || route(location.hash);
56
- }
57
- });
58
- }
59
- export type StatelessComponent<T = {}> = (args: T) => string | VNode | void;
60
- export { App, app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment, safeHTML }
61
- export { update as event };
62
- export { ROUTER_EVENT, ROUTER_404_EVENT };
63
- export { customElement, CustomElementOptions, AppStartOptions };
64
- export default app as IApp;
59
+ if (typeof document === 'object') {
60
+ document.addEventListener("DOMContentLoaded", () => {
61
+ if (app['route'] === route) {
62
+ window.onpopstate = () => route(location.hash);
63
+ document.body.hasAttribute('apprun-no-init') || app['no-init-route'] || route(location.hash);
64
+ }
65
+ });
66
+ }
65
67
 
66
- if (typeof window === 'object') {
67
- window['Component'] = Component;
68
- window['_React'] = window['React'];
69
- window['React'] = app;
70
- window['on'] = on;
71
- window['customElement'] = customElement;
72
- window['safeHTML'] = safeHTML;
73
- }
68
+ if (typeof window === 'object') {
69
+ window['Component'] = Component;
70
+ window['_React'] = window['React'];
71
+ window['React'] = app;
72
+ window['on'] = on;
73
+ window['customElement'] = customElement;
74
+ window['safeHTML'] = safeHTML;
75
+ }
74
76
 
75
- app.use_render = (render, mode = 0) =>
76
- mode === 0 ?
77
- app.render = (el, vdom) => render(vdom, el) : // react style
78
- app.render = (el, vdom) => render(el, vdom); // apprun style
77
+ app.use_render = (render, mode = 0) =>
78
+ mode === 0 ?
79
+ app.render = (el, vdom) => render(vdom, el) : // react style
80
+ app.render = (el, vdom) => render(el, vdom); // apprun style
79
81
 
80
- app.use_react = (React, ReactDOM) => {
81
- app.h = app.createElement = React.createElement;
82
- app.Fragment = React.Fragment;
83
- app.render = (el, vdom) => ReactDOM.render(vdom, el);
84
- if (React.version && React.version.startsWith('18')) {
85
- app.render = (el, vdom) => {
86
- if (!el || !vdom) return;
87
- if (!el._root) el._root = ReactDOM.createRoot(el);
88
- el._root.render(vdom);
82
+ app.use_react = (React, ReactDOM) => {
83
+ app.h = app.createElement = React.createElement;
84
+ app.Fragment = React.Fragment;
85
+ app.render = (el, vdom) => ReactDOM.render(vdom, el);
86
+ if (React.version && React.version.startsWith('18')) {
87
+ app.render = (el, vdom) => {
88
+ if (!el || !vdom) return;
89
+ if (!el._root) el._root = ReactDOM.createRoot(el);
90
+ el._root.render(vdom);
91
+ }
89
92
  }
90
93
  }
91
94
  }