@lowdefy/engine 3.23.3 → 4.0.0-alpha.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 (49) hide show
  1. package/dist/Actions.js +229 -309
  2. package/dist/Blocks.js +560 -608
  3. package/dist/Events.js +119 -163
  4. package/dist/Requests.js +105 -144
  5. package/dist/State.js +56 -82
  6. package/dist/actions/createCallMethod.js +29 -0
  7. package/dist/actions/{Reset.js → createDisplayMessage.js} +6 -21
  8. package/dist/actions/createGetActions.js +27 -0
  9. package/dist/actions/createGetBlockId.js +20 -0
  10. package/dist/actions/createGetEvent.js +27 -0
  11. package/dist/actions/createGetGlobal.js +27 -0
  12. package/dist/actions/createGetInput.js +27 -0
  13. package/dist/actions/createGetPageId.js +20 -0
  14. package/dist/actions/createGetRequestDetails.js +27 -0
  15. package/dist/actions/{Message.js → createGetState.js} +13 -23
  16. package/dist/actions/createGetUrlQuery.js +27 -0
  17. package/dist/actions/createGetUser.js +27 -0
  18. package/dist/actions/createLink.js +20 -0
  19. package/dist/actions/createLogin.js +20 -0
  20. package/dist/actions/createLogout.js +20 -0
  21. package/dist/actions/createRequest.js +25 -0
  22. package/dist/actions/createReset.js +23 -0
  23. package/dist/actions/createResetValidation.js +21 -0
  24. package/dist/actions/createSetGlobal.js +25 -0
  25. package/dist/actions/createSetState.js +25 -0
  26. package/dist/actions/createValidate.js +25 -0
  27. package/dist/actions/getActionMethods.js +61 -0
  28. package/dist/actions/getFromObject.js +42 -0
  29. package/dist/createLink.js +53 -60
  30. package/dist/getBlockMatcher.js +47 -59
  31. package/dist/getContext.js +106 -143
  32. package/dist/index.js +10 -71
  33. package/package.json +13 -13
  34. package/dist/actions/CallMethod.js +0 -47
  35. package/dist/actions/JsAction.js +0 -77
  36. package/dist/actions/Link.js +0 -38
  37. package/dist/actions/Login.js +0 -43
  38. package/dist/actions/Logout.js +0 -42
  39. package/dist/actions/Request.js +0 -65
  40. package/dist/actions/ResetValidation.js +0 -32
  41. package/dist/actions/ScrollTo.js +0 -52
  42. package/dist/actions/SetGlobal.js +0 -35
  43. package/dist/actions/SetState.js +0 -35
  44. package/dist/actions/Throw.js +0 -67
  45. package/dist/actions/Validate.js +0 -37
  46. package/dist/actions/Wait.js +0 -34
  47. package/dist/actions/index.js +0 -72
  48. package/dist/getFieldValues.js +0 -49
  49. package/dist/makeContextId.js +0 -44
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { applyArrayIndices } from '@lowdefy/helpers';
16
+ function createSetState({ arrayIndices , context }) {
17
+ return function setState(params) {
18
+ Object.keys(params).forEach((key)=>{
19
+ context._internal.State.set(applyArrayIndices(arrayIndices, key), params[key]);
20
+ });
21
+ context._internal.RootBlocks.reset();
22
+ context._internal.update();
23
+ };
24
+ }
25
+ export default createSetState;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import getBlockMatcher from '../getBlockMatcher.js';
16
+ function createValidate({ context }) {
17
+ return function validate(params) {
18
+ const validationErrors = context._internal.RootBlocks.validate(getBlockMatcher(params));
19
+ if (validationErrors.length > 0) {
20
+ const error = new Error(`Your input has ${validationErrors.length} validation error${validationErrors.length !== 1 ? 's' : ''}.`);
21
+ throw error;
22
+ }
23
+ };
24
+ }
25
+ export default createValidate;
@@ -0,0 +1,61 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import createCallMethod from './createCallMethod.js';
16
+ import createGetActions from './createGetActions.js';
17
+ import createGetBlockId from './createGetBlockId.js';
18
+ import createGetEvent from './createGetEvent.js';
19
+ import createGetGlobal from './createGetGlobal.js';
20
+ import createGetInput from './createGetInput.js';
21
+ import createGetPageId from './createGetPageId.js';
22
+ import createGetRequestDetails from './createGetRequestDetails.js';
23
+ import createGetState from './createGetState.js';
24
+ import createGetUrlQuery from './createGetUrlQuery.js';
25
+ import createGetUser from './createGetUser.js';
26
+ import createLink from './createLink.js';
27
+ import createLogin from './createLogin.js';
28
+ import createLogout from './createLogout.js';
29
+ import createDisplayMessage from './createDisplayMessage.js';
30
+ import createRequest from './createRequest.js';
31
+ import createReset from './createReset.js';
32
+ import createResetValidation from './createResetValidation.js';
33
+ import createSetGlobal from './createSetGlobal.js';
34
+ import createSetState from './createSetState.js';
35
+ import createValidate from './createValidate.js';
36
+ function getActionMethods(props) {
37
+ return {
38
+ callMethod: createCallMethod(props),
39
+ displayMessage: createDisplayMessage(props),
40
+ getActions: createGetActions(props),
41
+ getBlockId: createGetBlockId(props),
42
+ getEvent: createGetEvent(props),
43
+ getGlobal: createGetGlobal(props),
44
+ getInput: createGetInput(props),
45
+ getPageId: createGetPageId(props),
46
+ getRequestDetails: createGetRequestDetails(props),
47
+ getState: createGetState(props),
48
+ getUrlQuery: createGetUrlQuery(props),
49
+ getUser: createGetUser(props),
50
+ link: createLink(props),
51
+ login: createLogin(props),
52
+ logout: createLogout(props),
53
+ request: createRequest(props),
54
+ reset: createReset(props),
55
+ resetValidation: createResetValidation(props),
56
+ setGlobal: createSetGlobal(props),
57
+ setState: createSetState(props),
58
+ validate: createValidate(props)
59
+ };
60
+ }
61
+ export default getActionMethods;
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
16
+ const getFromObject = ({ arrayIndices , location , method , object , params })=>{
17
+ if (params === true) params = {
18
+ all: true
19
+ };
20
+ if (type.isString(params) || type.isInt(params)) params = {
21
+ key: params
22
+ };
23
+ if (!type.isObject(params)) {
24
+ throw new Error(`Method Error: ${method} params must be of type string, integer, boolean or object. Received: ${JSON.stringify(params)} at ${location}.`);
25
+ }
26
+ if (params.key === null) return get(params, 'default', {
27
+ default: null,
28
+ copy: true
29
+ });
30
+ if (params.all === true) return serializer.copy(object);
31
+ if (!type.isString(params.key) && !type.isInt(params.key)) {
32
+ throw new Error(`Method Error: ${method} params.key must be of type string or integer. Received: ${JSON.stringify(params)} at ${location}.`);
33
+ }
34
+ return get(object, applyArrayIndices(arrayIndices, params.key), {
35
+ default: get(params, 'default', {
36
+ default: null,
37
+ copy: true
38
+ }),
39
+ copy: true
40
+ });
41
+ };
42
+ export default getFromObject;
@@ -1,16 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
- var _engine = require("@lowdefy/engine");
11
-
12
1
  /*
13
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
14
3
 
15
4
  Licensed under the Apache License, Version 2.0 (the "License");
16
5
  you may not use this file except in compliance with the License.
@@ -23,53 +12,57 @@ var _engine = require("@lowdefy/engine");
23
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
13
  See the License for the specific language governing permissions and
25
14
  limitations under the License.
26
- */
27
- function createLink(_ref) {
28
- var {
29
- backLink,
30
- lowdefy,
31
- newOriginLink,
32
- sameOriginLink
33
- } = _ref;
34
-
35
- function link(_ref2) {
36
- var {
37
- back,
38
- home,
39
- input,
40
- newTab,
41
- pageId,
42
- url,
43
- urlQuery
44
- } = _ref2;
45
-
46
- if (back) {
47
- return backLink();
15
+ */ import { type, urlQuery as urlQueryFn } from '@lowdefy/helpers';
16
+ function createLink({ backLink , disabledLink , lowdefy , newOriginLink , noLink , sameOriginLink }) {
17
+ function link(props) {
18
+ if (props.disabled === true) {
19
+ return disabledLink(props);
20
+ }
21
+ if ([
22
+ !props.pageId,
23
+ !props.back,
24
+ !props.home,
25
+ !props.url
26
+ ].filter((v)=>!v
27
+ ).length > 1) {
28
+ throw Error(`Invalid Link: To avoid ambiguity, only one of 'back', 'home', 'pageId' or 'url' can be defined.`);
29
+ }
30
+ if (props.back === true) {
31
+ // Cannot set input or urlQuery on back
32
+ return backLink(props);
33
+ }
34
+ const query = type.isNone(props.urlQuery) ? '' : `${urlQueryFn.stringify(props.urlQuery)}`;
35
+ if (props.home === true) {
36
+ const pathname = `/${lowdefy.home.configured ? '' : lowdefy.home.pageId}`;
37
+ return sameOriginLink({
38
+ ...props,
39
+ pathname,
40
+ query,
41
+ setInput: ()=>{
42
+ lowdefy.inputs[`page:${lowdefy.home.pageId}`] = props.input || {};
43
+ }
44
+ });
45
+ }
46
+ if (type.isString(props.pageId)) {
47
+ return sameOriginLink({
48
+ ...props,
49
+ pathname: `/${props.pageId}`,
50
+ query,
51
+ setInput: ()=>{
52
+ lowdefy.inputs[`page:${props.pageId}`] = props.input || {};
53
+ }
54
+ });
55
+ }
56
+ if (type.isString(props.url)) {
57
+ const protocol = props.url.includes(':') ? '' : 'https://';
58
+ return newOriginLink({
59
+ ...props,
60
+ url: `${protocol}${props.url}`,
61
+ query
62
+ });
63
+ }
64
+ return noLink(props);
48
65
  }
49
-
50
- var lowdefyUrlQuery = _helpers.type.isNone(urlQuery) ? '' : "?".concat(_helpers.urlQuery.stringify(urlQuery));
51
- if (home) pageId = lowdefy.homePageId;
52
-
53
- if (pageId) {
54
- if (!_helpers.type.isNone(input)) {
55
- var nextContextId = (0, _engine.makeContextId)({
56
- pageId,
57
- urlQuery: urlQuery,
58
- blockId: pageId
59
- });
60
- lowdefy.inputs[nextContextId] = input;
61
- }
62
-
63
- return sameOriginLink("/".concat(pageId).concat(lowdefyUrlQuery), newTab);
64
- } else if (url) {
65
- return newOriginLink("".concat(url).concat(lowdefyUrlQuery), newTab);
66
- } else {
67
- throw new Error("Invalid Link.");
68
- }
69
- }
70
-
71
- return link;
66
+ return link;
72
67
  }
73
-
74
- var _default = createLink;
75
- exports.default = _default;
68
+ export default createLink;
@@ -1,14 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
1
  /*
11
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
12
3
 
13
4
  Licensed under the Apache License, Version 2.0 (the "License");
14
5
  you may not use this file except in compliance with the License.
@@ -21,55 +12,52 @@ var _helpers = require("@lowdefy/helpers");
21
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
13
  See the License for the specific language governing permissions and
23
14
  limitations under the License.
24
- */
25
- var getBlockMatcher = params => {
26
- var testParams = params;
27
- if (_helpers.type.isNone(testParams)) return () => true;
28
-
29
- if (_helpers.type.isString(testParams)) {
30
- testParams = {
31
- blockIds: [testParams]
32
- };
33
- }
34
-
35
- if (_helpers.type.isArray(testParams) || _helpers.type.isBoolean(testParams)) {
36
- testParams = {
37
- blockIds: testParams
38
- };
39
- }
40
-
41
- if (!_helpers.type.isObject(testParams)) {
42
- throw new Error('Invalid validate params.');
43
- }
44
-
45
- if (_helpers.type.isString(testParams.blockIds)) {
46
- testParams.blockIds = [testParams.blockIds];
47
- }
48
-
49
- if (_helpers.type.isString(testParams.regex)) {
50
- testParams.regex = [testParams.regex];
51
- }
52
-
53
- if (_helpers.type.isArray(testParams.regex)) {
54
- testParams.regex = testParams.regex.map(regex => new RegExp(regex));
55
- }
56
-
57
- return id => {
58
- if (testParams.blockIds === true || _helpers.type.isArray(testParams.blockIds) && testParams.blockIds.includes(id)) {
59
- return true;
15
+ */ import { type } from '@lowdefy/helpers';
16
+ const getBlockMatcher = (params)=>{
17
+ let testParams = params;
18
+ if (type.isNone(testParams)) return ()=>true
19
+ ;
20
+ if (type.isString(testParams)) {
21
+ testParams = {
22
+ blockIds: [
23
+ testParams
24
+ ]
25
+ };
60
26
  }
61
-
62
- if (_helpers.type.isArray(testParams.regex)) {
63
- for (var regex of testParams.regex) {
64
- if (regex.test(id)) {
65
- return true;
66
- }
67
- }
27
+ if (type.isArray(testParams) || type.isBoolean(testParams)) {
28
+ testParams = {
29
+ blockIds: testParams
30
+ };
68
31
  }
69
-
70
- return false;
71
- };
32
+ if (!type.isObject(testParams)) {
33
+ throw new Error('Invalid validate params.');
34
+ }
35
+ if (type.isString(testParams.blockIds)) {
36
+ testParams.blockIds = [
37
+ testParams.blockIds
38
+ ];
39
+ }
40
+ if (type.isString(testParams.regex)) {
41
+ testParams.regex = [
42
+ testParams.regex
43
+ ];
44
+ }
45
+ if (type.isArray(testParams.regex)) {
46
+ testParams.regex = testParams.regex.map((regex)=>new RegExp(regex)
47
+ );
48
+ }
49
+ return (id)=>{
50
+ if (testParams.blockIds === true || type.isArray(testParams.blockIds) && testParams.blockIds.includes(id)) {
51
+ return true;
52
+ }
53
+ if (type.isArray(testParams.regex)) {
54
+ for (const regex of testParams.regex){
55
+ if (regex.test(id)) {
56
+ return true;
57
+ }
58
+ }
59
+ }
60
+ return false;
61
+ };
72
62
  };
73
-
74
- var _default = getBlockMatcher;
75
- exports.default = _default;
63
+ export default getBlockMatcher;
@@ -1,151 +1,114 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _operators = require("@lowdefy/operators");
9
-
10
- var _Actions = _interopRequireDefault(require("./Actions"));
11
-
12
- var _Blocks = _interopRequireDefault(require("./Blocks"));
13
-
14
- var _Requests = _interopRequireDefault(require("./Requests"));
15
-
16
- var _State = _interopRequireDefault(require("./State"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
-
22
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
-
24
- var blockData = _ref => {
25
- var {
26
- areas,
27
- blockId,
28
- blocks,
29
- events,
30
- field,
31
- id,
32
- layout,
33
- meta,
34
- operators,
35
- pageId,
36
- properties,
37
- requests,
38
- required,
39
- style,
40
- type,
41
- validate,
42
- visible
43
- } = _ref;
44
- return {
45
- areas,
46
- blockId,
47
- blocks,
48
- events,
49
- field,
50
- id,
51
- layout,
52
- meta,
53
- operators,
54
- pageId,
55
- properties,
56
- requests,
57
- required,
58
- style,
59
- type,
60
- validate,
61
- visible
62
- };
63
- };
64
-
65
- var getContext = /*#__PURE__*/function () {
66
- var _ref3 = _asyncToGenerator(function* (_ref2) {
67
- var {
68
- block,
69
- contextId,
70
- lowdefy
71
- } = _ref2;
72
-
73
- if (lowdefy.contexts[contextId]) {
74
- lowdefy.contexts[contextId].update();
75
- return lowdefy.contexts[contextId];
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { WebParser } from '@lowdefy/operators';
16
+ import Actions from './Actions.js';
17
+ import Blocks from './Blocks.js';
18
+ import Requests from './Requests.js';
19
+ import State from './State.js';
20
+ const blockData = ({ areas , blockId , blocks , events , field , id , layout , pageId , properties , requests , required , style , type , validate , visible , })=>({
21
+ areas,
22
+ blockId,
23
+ blocks,
24
+ events,
25
+ field,
26
+ id,
27
+ layout,
28
+ pageId,
29
+ properties,
30
+ requests,
31
+ required,
32
+ style,
33
+ type,
34
+ validate,
35
+ visible
36
+ })
37
+ ;
38
+ function getContext({ config , lowdefy , resetContext ={
39
+ reset: false,
40
+ setReset: ()=>undefined
41
+ } , }) {
42
+ if (!config) {
43
+ throw new Error('A page must be provided to get context.');
76
44
  }
77
-
78
- if (!block) {
79
- throw new Error('A block must be provided to get context.');
80
- } // eslint-disable-next-line no-param-reassign
81
-
82
-
83
- if (!lowdefy.inputs[contextId]) {
84
- lowdefy.inputs[contextId] = {};
45
+ const { id } = config;
46
+ if (lowdefy.contexts[id] && !resetContext.reset) {
47
+ // memoize context if already created, eg between page transitions, unless the reset flag is raised
48
+ lowdefy.contexts[id]._internal.update();
49
+ return lowdefy.contexts[id];
85
50
  }
86
-
87
- var operatorsSet = new Set([...block.operators, '_not', '_type']);
88
- lowdefy.contexts[contextId] = {
89
- id: contextId,
90
- blockId: block.blockId,
91
- eventLog: [],
92
- requests: {},
93
- operators: [...operatorsSet],
94
- lowdefy,
95
- pageId: lowdefy.pageId,
96
- rootBlock: blockData(block),
97
- // filter block to prevent circular structure
98
- state: {},
99
- update: () => {},
100
- // Initialize update since Requests might call it during context creation
101
- updateListeners: new Set()
51
+ resetContext.setReset(false); // lower context reset flag.
52
+ if (!lowdefy.inputs[id]) {
53
+ lowdefy.inputs[id] = {};
54
+ }
55
+ const ctx = {
56
+ id: id,
57
+ pageId: config.pageId,
58
+ eventLog: [],
59
+ requests: {},
60
+ state: {},
61
+ _internal: {
62
+ lowdefy,
63
+ rootBlock: blockData(config),
64
+ update: ()=>{}
65
+ }
102
66
  };
103
- var ctx = lowdefy.contexts[contextId];
104
- ctx.parser = new _operators.WebParser({
105
- context: ctx,
106
- contexts: lowdefy.contexts
67
+ const _internal = ctx._internal;
68
+ _internal.parser = new WebParser({
69
+ context: ctx,
70
+ operators: lowdefy._internal.operators
107
71
  });
108
- yield ctx.parser.init();
109
- ctx.State = new _State.default(ctx);
110
- ctx.Actions = new _Actions.default(ctx);
111
- ctx.Requests = new _Requests.default(ctx);
112
- ctx.RootBlocks = new _Blocks.default({
113
- areas: {
114
- root: {
115
- blocks: [ctx.rootBlock]
116
- }
117
- },
118
- context: ctx
72
+ _internal.State = new State(ctx);
73
+ _internal.Actions = new Actions(ctx);
74
+ _internal.Requests = new Requests(ctx);
75
+ _internal.RootBlocks = new Blocks({
76
+ areas: {
77
+ root: {
78
+ blocks: [
79
+ _internal.rootBlock
80
+ ]
81
+ }
82
+ },
83
+ context: ctx
119
84
  });
120
- ctx.RootBlocks.init();
121
-
122
- ctx.update = () => {
123
- ctx.RootBlocks.update();
124
- [...ctx.updateListeners].forEach(listenId => {
125
- // Will loop infinitely if update is called on self
126
- if (!lowdefy.contexts[listenId] || listenId === contextId) {
127
- ctx.updateListeners.delete(listenId);
128
- } else {
129
- lowdefy.contexts[listenId].update();
85
+ _internal.RootBlocks.init();
86
+ _internal.update = ()=>{
87
+ _internal.RootBlocks.update();
88
+ };
89
+ _internal.runOnInit = async (progress)=>{
90
+ progress();
91
+ if (!_internal.onInitDone) {
92
+ await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
93
+ name: 'onInit',
94
+ progress
95
+ });
96
+ _internal.update();
97
+ _internal.State.freezeState();
98
+ _internal.onInitDone = true;
130
99
  }
131
- });
132
100
  };
133
-
134
- yield ctx.RootBlocks.map[ctx.blockId].triggerEvent({
135
- name: 'onInit'
136
- });
137
- ctx.update();
138
- ctx.State.freezeState();
139
- ctx.RootBlocks.map[ctx.blockId].triggerEvent({
140
- name: 'onInitAsync'
141
- });
101
+ _internal.runOnInitAsync = async (progress)=>{
102
+ if (_internal.onInitDone && !_internal.onInitAsyncDone) {
103
+ await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
104
+ name: 'onInitAsync',
105
+ progress
106
+ });
107
+ _internal.onInitAsyncDone = true;
108
+ }
109
+ };
110
+ ctx._internal.update();
111
+ lowdefy.contexts[id] = ctx;
142
112
  return ctx;
143
- });
144
-
145
- return function getContext(_x) {
146
- return _ref3.apply(this, arguments);
147
- };
148
- }();
149
-
150
- var _default = getContext;
151
- exports.default = _default;
113
+ }
114
+ export default getContext;