@domql/state 2.5.198 → 3.0.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/create.js CHANGED
@@ -1,35 +1,15 @@
1
1
  'use strict'
2
2
 
3
3
  import { triggerEventOn } from '@domql/event'
4
- import { deepClone, exec, is, isArray, isFunction, isObject, isUndefined } from '@domql/utils'
5
- import { IGNORE_STATE_PARAMS } from './ignore.js'
6
4
  import {
7
- add,
8
- apply,
9
- applyFunction,
10
- clean,
11
- destroy,
12
- parentUpdate,
13
- parse,
14
- remove,
15
- rootUpdate,
16
- set,
17
- reset,
18
- toggle,
19
- replace,
20
- quietUpdate,
21
- quietReplace,
22
- applyReplace,
23
- setByPath,
24
- setPathCollection,
25
- removeByPath,
26
- removePathCollection,
27
- getByPath,
28
- keys,
29
- values
30
- } from './methods.js'
31
- import { updateState } from './updateState.js'
32
- import { checkIfInherits, createInheritedState } from './inherit.js'
5
+ applyDependentState,
6
+ checkForStateTypes,
7
+ checkIfInherits,
8
+ createInheritedState,
9
+ isUndefined
10
+ } from '@domql/utils'
11
+
12
+ import { applyStateMethods } from './methods'
33
13
 
34
14
  export const createState = async function (element, parent, options) {
35
15
  element.state = await applyInitialState(element, parent, options)
@@ -37,11 +17,11 @@ export const createState = async function (element, parent, options) {
37
17
  }
38
18
 
39
19
  export const applyInitialState = async function (element, parent, options) {
40
- const objectizeState = await checkForTypes(element)
20
+ const objectizeState = await checkForStateTypes(element)
41
21
  if (objectizeState === false) return parent.state || {}
42
22
  else element.state = objectizeState
43
23
 
44
- const whatInitReturns = triggerEventOn('stateInit', element, options)
24
+ const whatInitReturns = await triggerEventOn('stateInit', element, options)
45
25
  if (whatInitReturns === false) return element.state
46
26
 
47
27
  if (checkIfInherits(element)) {
@@ -49,111 +29,16 @@ export const applyInitialState = async function (element, parent, options) {
49
29
  element.state = isUndefined(inheritedState) ? {} : inheritedState
50
30
  }
51
31
 
52
- const dependentState = applyDependentState(element, element.state || parent.state || {})
32
+ const dependentState = await applyDependentState(
33
+ element,
34
+ element.state || parent.state || {}
35
+ )
53
36
  if (dependentState) element.state = dependentState
54
37
 
55
- applyMethods(element)
38
+ applyStateMethods(element)
56
39
 
57
40
  // trigger `on.stateCreated`
58
- triggerEventOn('stateCreated', element)
41
+ await triggerEventOn('stateCreated', element)
59
42
 
60
43
  return element.state
61
44
  }
62
-
63
- const applyDependentState = (element, state) => {
64
- const { __ref, ref, __element } = state //
65
- const origState = exec(__ref || ref || __element?.state, element)
66
- if (!origState) return
67
- const dependentState = deepClone(origState, IGNORE_STATE_PARAMS)
68
- const newDepends = { [element.key]: dependentState }
69
-
70
- const __depends = isObject(origState.__depends)
71
- ? { ...origState.__depends, ...newDepends }
72
- : newDepends
73
-
74
- if (Array.isArray(origState)) {
75
- addProtoToArray(origState, { ...Object.getPrototypeOf(origState), __depends })
76
- } else {
77
- Object.setPrototypeOf(origState, { ...Object.getPrototypeOf(origState), __depends })
78
- }
79
-
80
- return dependentState
81
- }
82
-
83
- const checkForTypes = async (element) => {
84
- const { state: orig, props, __ref: ref } = element
85
- const state = props?.state || orig
86
- if (isFunction(state)) {
87
- ref.__state = state
88
- return await exec(state, element)
89
- } else if (is(state)('string', 'number')) {
90
- ref.__state = state
91
- return { value: state }
92
- } else if (state === true) {
93
- ref.__state = element.key
94
- return {}
95
- } else if (state) {
96
- ref.__hasRootState = true
97
- return state
98
- } else {
99
- return false
100
- }
101
- }
102
-
103
- const addProtoToArray = (state, proto) => {
104
- for (const key in proto) {
105
- Object.defineProperty(state, key, {
106
- value: proto[key],
107
- enumerable: false, // Set this to true if you want the method to appear in for...in loops
108
- configurable: true, // Set this to true if you want to allow redefining/removing the property later
109
- writable: true // Set this to true if you want to allow changing the function later
110
- })
111
- }
112
- }
113
-
114
- const applyMethods = (element) => {
115
- const state = element.state
116
- const ref = element.__ref
117
-
118
- const proto = {
119
- clean: clean.bind(state),
120
- parse: parse.bind(state),
121
- destroy: destroy.bind(state),
122
- update: updateState.bind(state),
123
- rootUpdate: rootUpdate.bind(state),
124
- parentUpdate: parentUpdate.bind(state),
125
- create: createState.bind(state),
126
- add: add.bind(state),
127
- toggle: toggle.bind(state),
128
- remove: remove.bind(state),
129
- apply: apply.bind(state),
130
- applyReplace: applyReplace.bind(state),
131
- applyFunction: applyFunction.bind(state),
132
- set: set.bind(state),
133
- quietUpdate: quietUpdate.bind(state),
134
- replace: replace.bind(state),
135
- quietReplace: quietReplace.bind(state),
136
- reset: reset.bind(state),
137
- parent: element.parent.state || state,
138
-
139
- setByPath: setByPath.bind(state),
140
- setPathCollection: setPathCollection.bind(state),
141
- removeByPath: removeByPath.bind(state),
142
- removePathCollection: removePathCollection.bind(state),
143
- getByPath: getByPath.bind(state),
144
-
145
- keys: keys.bind(state),
146
- values: values.bind(state),
147
- __element: element,
148
- __children: {},
149
- root: ref.root ? ref.root.state : state
150
- }
151
-
152
- if (isArray(state)) {
153
- addProtoToArray(state, proto)
154
- } else {
155
- Object.setPrototypeOf(state, proto)
156
- }
157
-
158
- if (state.parent && state.parent.__children) { state.parent.__children[element.key] = state }
159
- }
@@ -24,121 +24,27 @@ __export(create_exports, {
24
24
  module.exports = __toCommonJS(create_exports);
25
25
  var import_event = require("@domql/event");
26
26
  var import_utils = require("@domql/utils");
27
- var import_ignore = require("./ignore.js");
28
- var import_methods = require("./methods.js");
29
- var import_updateState = require("./updateState.js");
30
- var import_inherit = require("./inherit.js");
27
+ var import_methods = require("./methods");
31
28
  const createState = async function(element, parent, options) {
32
29
  element.state = await applyInitialState(element, parent, options);
33
30
  return element.state;
34
31
  };
35
32
  const applyInitialState = async function(element, parent, options) {
36
- const objectizeState = await checkForTypes(element);
37
- if (objectizeState === false)
38
- return parent.state || {};
39
- else
40
- element.state = objectizeState;
41
- const whatInitReturns = (0, import_event.triggerEventOn)("stateInit", element, options);
42
- if (whatInitReturns === false)
43
- return element.state;
44
- if ((0, import_inherit.checkIfInherits)(element)) {
45
- const inheritedState = (0, import_inherit.createInheritedState)(element, parent);
33
+ const objectizeState = await (0, import_utils.checkForStateTypes)(element);
34
+ if (objectizeState === false) return parent.state || {};
35
+ else element.state = objectizeState;
36
+ const whatInitReturns = await (0, import_event.triggerEventOn)("stateInit", element, options);
37
+ if (whatInitReturns === false) return element.state;
38
+ if ((0, import_utils.checkIfInherits)(element)) {
39
+ const inheritedState = (0, import_utils.createInheritedState)(element, parent);
46
40
  element.state = (0, import_utils.isUndefined)(inheritedState) ? {} : inheritedState;
47
41
  }
48
- const dependentState = applyDependentState(element, element.state || parent.state || {});
49
- if (dependentState)
50
- element.state = dependentState;
51
- applyMethods(element);
52
- (0, import_event.triggerEventOn)("stateCreated", element);
42
+ const dependentState = await (0, import_utils.applyDependentState)(
43
+ element,
44
+ element.state || parent.state || {}
45
+ );
46
+ if (dependentState) element.state = dependentState;
47
+ (0, import_methods.applyStateMethods)(element);
48
+ await (0, import_event.triggerEventOn)("stateCreated", element);
53
49
  return element.state;
54
50
  };
55
- const applyDependentState = (element, state) => {
56
- const { __ref, ref, __element } = state;
57
- const origState = (0, import_utils.exec)(__ref || ref || (__element == null ? void 0 : __element.state), element);
58
- if (!origState)
59
- return;
60
- const dependentState = (0, import_utils.deepClone)(origState, import_ignore.IGNORE_STATE_PARAMS);
61
- const newDepends = { [element.key]: dependentState };
62
- const __depends = (0, import_utils.isObject)(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
63
- if (Array.isArray(origState)) {
64
- addProtoToArray(origState, { ...Object.getPrototypeOf(origState), __depends });
65
- } else {
66
- Object.setPrototypeOf(origState, { ...Object.getPrototypeOf(origState), __depends });
67
- }
68
- return dependentState;
69
- };
70
- const checkForTypes = async (element) => {
71
- const { state: orig, props, __ref: ref } = element;
72
- const state = (props == null ? void 0 : props.state) || orig;
73
- if ((0, import_utils.isFunction)(state)) {
74
- ref.__state = state;
75
- return await (0, import_utils.exec)(state, element);
76
- } else if ((0, import_utils.is)(state)("string", "number")) {
77
- ref.__state = state;
78
- return { value: state };
79
- } else if (state === true) {
80
- ref.__state = element.key;
81
- return {};
82
- } else if (state) {
83
- ref.__hasRootState = true;
84
- return state;
85
- } else {
86
- return false;
87
- }
88
- };
89
- const addProtoToArray = (state, proto) => {
90
- for (const key in proto) {
91
- Object.defineProperty(state, key, {
92
- value: proto[key],
93
- enumerable: false,
94
- // Set this to true if you want the method to appear in for...in loops
95
- configurable: true,
96
- // Set this to true if you want to allow redefining/removing the property later
97
- writable: true
98
- // Set this to true if you want to allow changing the function later
99
- });
100
- }
101
- };
102
- const applyMethods = (element) => {
103
- const state = element.state;
104
- const ref = element.__ref;
105
- const proto = {
106
- clean: import_methods.clean.bind(state),
107
- parse: import_methods.parse.bind(state),
108
- destroy: import_methods.destroy.bind(state),
109
- update: import_updateState.updateState.bind(state),
110
- rootUpdate: import_methods.rootUpdate.bind(state),
111
- parentUpdate: import_methods.parentUpdate.bind(state),
112
- create: createState.bind(state),
113
- add: import_methods.add.bind(state),
114
- toggle: import_methods.toggle.bind(state),
115
- remove: import_methods.remove.bind(state),
116
- apply: import_methods.apply.bind(state),
117
- applyReplace: import_methods.applyReplace.bind(state),
118
- applyFunction: import_methods.applyFunction.bind(state),
119
- set: import_methods.set.bind(state),
120
- quietUpdate: import_methods.quietUpdate.bind(state),
121
- replace: import_methods.replace.bind(state),
122
- quietReplace: import_methods.quietReplace.bind(state),
123
- reset: import_methods.reset.bind(state),
124
- parent: element.parent.state || state,
125
- setByPath: import_methods.setByPath.bind(state),
126
- setPathCollection: import_methods.setPathCollection.bind(state),
127
- removeByPath: import_methods.removeByPath.bind(state),
128
- removePathCollection: import_methods.removePathCollection.bind(state),
129
- getByPath: import_methods.getByPath.bind(state),
130
- keys: import_methods.keys.bind(state),
131
- values: import_methods.values.bind(state),
132
- __element: element,
133
- __children: {},
134
- root: ref.root ? ref.root.state : state
135
- };
136
- if ((0, import_utils.isArray)(state)) {
137
- addProtoToArray(state, proto);
138
- } else {
139
- Object.setPrototypeOf(state, proto);
140
- }
141
- if (state.parent && state.parent.__children) {
142
- state.parent.__children[element.key] = state;
143
- }
144
- };
package/dist/cjs/index.js CHANGED
@@ -13,10 +13,8 @@ var __copyProps = (to, from, except, desc) => {
13
13
  };
14
14
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var state_exports = {};
17
- module.exports = __toCommonJS(state_exports);
18
- __reExport(state_exports, require("./ignore.js"), module.exports);
19
- __reExport(state_exports, require("./create.js"), module.exports);
20
- __reExport(state_exports, require("./updateState.js"), module.exports);
21
- __reExport(state_exports, require("./methods.js"), module.exports);
22
- __reExport(state_exports, require("./inherit.js"), module.exports);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./create.js"), module.exports);
19
+ __reExport(index_exports, require("./updateState.js"), module.exports);
20
+ __reExport(index_exports, require("./methods.js"), module.exports);
@@ -22,6 +22,7 @@ __export(methods_exports, {
22
22
  apply: () => apply,
23
23
  applyFunction: () => applyFunction,
24
24
  applyReplace: () => applyReplace,
25
+ applyStateMethods: () => applyStateMethods,
25
26
  clean: () => clean,
26
27
  destroy: () => destroy,
27
28
  getByPath: () => getByPath,
@@ -44,34 +45,35 @@ __export(methods_exports, {
44
45
  });
45
46
  module.exports = __toCommonJS(methods_exports);
46
47
  var import_utils = require("@domql/utils");
47
- var import_ignore = require("./ignore.js");
48
+ var import_updateState = require("./updateState.js");
49
+ var import_create = require("./create.js");
48
50
  const parse = function() {
49
51
  const state = this;
50
52
  if ((0, import_utils.isObject)(state)) {
51
53
  const obj = {};
52
54
  for (const param in state) {
53
- if (!import_ignore.IGNORE_STATE_PARAMS.includes(param)) {
55
+ if (!import_utils.STATE_METHODS.includes(param)) {
54
56
  obj[param] = state[param];
55
57
  }
56
58
  }
57
59
  return obj;
58
60
  } else if ((0, import_utils.isArray)(state)) {
59
- return state.filter((item) => !import_ignore.IGNORE_STATE_PARAMS.includes(item));
61
+ return state.filter((item) => !import_utils.STATE_METHODS.includes(item));
60
62
  }
61
63
  };
62
- const clean = function(options = {}) {
64
+ const clean = async function(options = {}) {
63
65
  const state = this;
64
66
  for (const param in state) {
65
- if (!import_ignore.IGNORE_STATE_PARAMS.includes(param) && Object.hasOwnProperty.call(state, param)) {
67
+ if (!import_utils.STATE_METHODS.includes(param) && Object.hasOwnProperty.call(state, param)) {
66
68
  delete state[param];
67
69
  }
68
70
  }
69
71
  if (!options.preventStateUpdate) {
70
- state.update(state, { replace: true, ...options });
72
+ await state.update(state, { replace: true, ...options });
71
73
  }
72
74
  return state;
73
75
  };
74
- const destroy = function(options = {}) {
76
+ const destroy = async function(options = {}) {
75
77
  const state = this;
76
78
  const element = state.__element;
77
79
  const stateKey = element.__ref.__state;
@@ -104,131 +106,133 @@ const destroy = function(options = {}) {
104
106
  }
105
107
  }
106
108
  }
107
- element.state.update({}, { isHoisted: true, ...options });
109
+ await element.state.update({}, { isHoisted: true, ...options });
108
110
  return element.state;
109
111
  };
110
- const parentUpdate = function(obj, options = {}) {
112
+ const parentUpdate = async function(obj, options = {}) {
111
113
  const state = this;
112
- if (!state || !state.parent)
113
- return;
114
- return state.parent.update(obj, { isHoisted: true, ...options });
114
+ if (!state || !state.parent) return;
115
+ return await state.parent.update(obj, { isHoisted: true, ...options });
115
116
  };
116
- const rootUpdate = function(obj, options = {}) {
117
+ const rootUpdate = async function(obj, options = {}) {
117
118
  const state = this;
118
- if (!state)
119
- return;
119
+ if (!state) return;
120
120
  const rootState = state.__element.__ref.root.state;
121
- return rootState.update(obj, { isHoisted: false, ...options });
121
+ return await rootState.update(obj, { isHoisted: false, ...options });
122
122
  };
123
- const add = function(value, options = {}) {
123
+ const add = async function(value, options = {}) {
124
124
  const state = this;
125
125
  if ((0, import_utils.isArray)(state)) {
126
126
  state.push(value);
127
- state.update(state.parse(), { overwrite: true, ...options });
127
+ await state.update(state.parse(), { overwrite: true, ...options });
128
128
  } else if ((0, import_utils.isObject)(state)) {
129
129
  const key = Object.keys(state).length;
130
- state.update({ [key]: value }, options);
130
+ await state.update({ [key]: value }, options);
131
131
  }
132
132
  };
133
- const toggle = function(key, options = {}) {
133
+ const toggle = async function(key, options = {}) {
134
134
  const state = this;
135
- state.update({ [key]: !state[key] }, options);
135
+ await state.update({ [key]: !state[key] }, options);
136
136
  };
137
- const remove = function(key, options = {}) {
137
+ const remove = async function(key, options = {}) {
138
138
  const state = this;
139
- if ((0, import_utils.isArray)(state))
140
- (0, import_utils.removeFromArray)(state, key);
141
- if ((0, import_utils.isObject)(state))
142
- (0, import_utils.removeFromObject)(state, key);
143
- if (options.applyReset)
144
- return state.set(state.parse(), { replace: true, ...options });
145
- return state.update();
139
+ if ((0, import_utils.isArray)(state)) (0, import_utils.removeFromArray)(state, key);
140
+ if ((0, import_utils.isObject)(state)) (0, import_utils.removeFromObject)(state, key);
141
+ if (options.applyReset) {
142
+ return await state.set(state.parse(), { replace: true, ...options });
143
+ }
144
+ return await state.update({}, options);
146
145
  };
147
- const set = function(val, options = {}) {
146
+ const set = async function(val, options = {}) {
148
147
  const state = this;
149
148
  const value = (0, import_utils.deepClone)(val);
150
- return state.clean({ preventStateUpdate: true, ...options }).update(value, { replace: true, ...options });
149
+ const cleanState = await state.clean({ preventStateUpdate: true, ...options });
150
+ return await cleanState.update(value, { replace: true, ...options });
151
151
  };
152
- const setByPath = function(path, val, options = {}) {
152
+ const setByPath = async function(path, val, options = {}) {
153
153
  const state = this;
154
154
  const value = (0, import_utils.deepClone)(val);
155
155
  (0, import_utils.setInObjectByPath)(state, path, val);
156
156
  const update = (0, import_utils.createNestedObject)(path, value);
157
- if (options.preventStateUpdate)
158
- return update;
159
- return state.update(update, options);
157
+ if (options.preventStateUpdate) return update;
158
+ return await state.update(update, options);
160
159
  };
161
- const setPathCollection = function(changes, options = {}) {
160
+ const setPathCollection = async function(changes, options = {}) {
162
161
  const state = this;
163
- const update = changes.reduce((acc, change) => {
162
+ const update = await changes.reduce(async (promise, change) => {
163
+ const acc = await promise;
164
164
  if (change[0] === "update") {
165
- const result = setByPath.call(state, change[1], change[2], { preventStateUpdate: true });
165
+ const result = setByPath.call(state, change[1], change[2], {
166
+ preventStateUpdate: true
167
+ });
166
168
  return (0, import_utils.overwriteDeep)(acc, result);
167
169
  } else if (change[0] === "delete") {
168
- removeByPath.call(state, change[1], options);
170
+ await removeByPath.call(state, change[1], {
171
+ ...options,
172
+ preventUpdate: true
173
+ });
169
174
  }
170
175
  return acc;
171
- }, {});
176
+ }, Promise.resolve({}));
172
177
  return state.update(update, options);
173
178
  };
174
- const removeByPath = function(path, options = {}) {
179
+ const removeByPath = async function(path, options = {}) {
175
180
  const state = this;
176
181
  (0, import_utils.removeNestedKeyByPath)(state, path);
177
- if (options.preventUpdate)
178
- return path;
179
- return state.update({}, options);
182
+ if (options.preventUpdate) return path;
183
+ return await state.update({}, options);
180
184
  };
181
- const removePathCollection = function(changes, options = {}) {
185
+ const removePathCollection = async function(changes, options = {}) {
182
186
  const state = this;
183
- changes.forEach((item) => {
184
- removeByPath(item, { preventUpdate: true });
187
+ changes.forEach(async (item) => {
188
+ await removeByPath(item, { preventUpdate: true });
185
189
  });
186
- return state.update({}, options);
190
+ return await state.update({}, options);
187
191
  };
188
192
  const getByPath = function(path, options = {}) {
189
193
  const state = this;
190
194
  return (0, import_utils.getInObjectByPath)(state, path);
191
195
  };
192
- const reset = function(options = {}) {
196
+ const reset = async function(options = {}) {
193
197
  const state = this;
194
198
  const value = (0, import_utils.deepClone)(state.parse());
195
- return state.set(value, { replace: true, ...options });
199
+ return await state.set(value, { replace: true, ...options });
196
200
  };
197
- const apply = function(func, options = {}) {
201
+ const apply = async function(func, options = {}) {
198
202
  const state = this;
199
203
  if ((0, import_utils.isFunction)(func)) {
200
204
  const value = func(state);
201
- return state.update(value, { replace: true, ...options });
205
+ return await state.update(value, { replace: true, ...options });
202
206
  }
203
207
  };
204
- const applyReplace = function(func, options = {}) {
208
+ const applyReplace = async function(func, options = {}) {
205
209
  const state = this;
206
210
  if ((0, import_utils.isFunction)(func)) {
207
211
  const value = func(state);
208
- return state.replace(value, options);
212
+ return await state.replace(value, options);
209
213
  }
210
214
  };
211
- const applyFunction = function(func, options = {}) {
215
+ const applyFunction = async function(func, options = {}) {
212
216
  const state = this;
213
217
  if ((0, import_utils.isFunction)(func)) {
214
- func(state);
215
- return state.update(state.parse(), { replace: true, ...options });
218
+ await func(state);
219
+ return await state.update(state.parse(), { replace: true, ...options });
216
220
  }
217
221
  };
218
- const quietUpdate = function(obj, options = {}) {
222
+ const quietUpdate = async function(obj, options = {}) {
219
223
  const state = this;
220
- return state.update(obj, { preventUpdate: true, ...options });
224
+ return await state.update(obj, { preventUpdate: true, ...options });
221
225
  };
222
- const replace = function(obj, options = {}) {
226
+ const replace = async function(obj, options = {}) {
223
227
  const state = this;
224
228
  for (const param in obj) {
225
229
  state[param] = obj[param];
226
230
  }
227
- return state.update(obj, options);
231
+ return await state.update(obj, options);
228
232
  };
229
- const quietReplace = function(obj, options = {}) {
233
+ const quietReplace = async function(obj, options = {}) {
230
234
  const state = this;
231
- return state.replace(obj, { preventUpdate: true, ...options });
235
+ return await state.replace(obj, { preventUpdate: true, ...options });
232
236
  };
233
237
  const keys = function(obj, options = {}) {
234
238
  const state = this;
@@ -238,3 +242,47 @@ const values = function(obj, options = {}) {
238
242
  const state = this;
239
243
  return Object.values(state);
240
244
  };
245
+ const applyStateMethods = (element) => {
246
+ var _a;
247
+ const state = element.state;
248
+ const ref = element.__ref;
249
+ const proto = {
250
+ clean: clean.bind(state),
251
+ parse: parse.bind(state),
252
+ destroy: destroy.bind(state),
253
+ update: import_updateState.updateState.bind(state),
254
+ rootUpdate: rootUpdate.bind(state),
255
+ parentUpdate: parentUpdate.bind(state),
256
+ create: import_create.createState.bind(state),
257
+ add: add.bind(state),
258
+ toggle: toggle.bind(state),
259
+ remove: remove.bind(state),
260
+ apply: apply.bind(state),
261
+ applyReplace: applyReplace.bind(state),
262
+ applyFunction: applyFunction.bind(state),
263
+ set: set.bind(state),
264
+ quietUpdate: quietUpdate.bind(state),
265
+ replace: replace.bind(state),
266
+ quietReplace: quietReplace.bind(state),
267
+ reset: reset.bind(state),
268
+ parent: ((_a = element.parent) == null ? void 0 : _a.state) || state,
269
+ setByPath: setByPath.bind(state),
270
+ setPathCollection: setPathCollection.bind(state),
271
+ removeByPath: removeByPath.bind(state),
272
+ removePathCollection: removePathCollection.bind(state),
273
+ getByPath: getByPath.bind(state),
274
+ keys: keys.bind(state),
275
+ values: values.bind(state),
276
+ __element: element,
277
+ __children: {},
278
+ root: (ref == null ? void 0 : ref.root) ? ref.root.state : state
279
+ };
280
+ if ((0, import_utils.isArray)(state)) {
281
+ (0, import_utils.addProtoToArray)(state, proto);
282
+ } else {
283
+ Object.setPrototypeOf(state, proto);
284
+ }
285
+ if (state.parent && state.parent.__children) {
286
+ state.parent.__children[element.key] = state;
287
+ }
288
+ };