tungsten 0.1.44 → 0.1.46
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/dist/__deproxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__deproxy.d.ts","sourceRoot":"","sources":["../src/__deproxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"__deproxy.d.ts","sourceRoot":"","sources":["../src/__deproxy.ts"],"names":[],"mappings":"AAKA,wBAAgB,SAAS,CAAC,aAAa,EAAE,OAAO,WAW/C;AAED,eAAO,MAAM,IAAI,kBAAY,CAAA"}
|
package/dist/__deproxy.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { $original } from "./componentProxyHandlers.js";
|
|
1
2
|
import { NoDeproxy } from "./NoDeproxy.js";
|
|
3
|
+
// doesn't this need to be deep?
|
|
2
4
|
export function __deproxy(possibleProxy) {
|
|
5
|
+
console.log('__deproxy called, this function may not be adequate');
|
|
3
6
|
if (possibleProxy instanceof NoDeproxy) {
|
|
4
7
|
return possibleProxy.value;
|
|
5
8
|
} else if (typeof possibleProxy === 'object' && possibleProxy !== null) {
|
|
6
|
-
if ('__original' in possibleProxy) {
|
|
7
|
-
|
|
9
|
+
//if ('__original' in possibleProxy) {
|
|
10
|
+
if ($original in possibleProxy) {
|
|
11
|
+
return possibleProxy[$original];
|
|
8
12
|
}
|
|
9
13
|
}
|
|
10
14
|
return possibleProxy;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TungstenStatefulComponent, TungstenComponent } from './Components.jsx';
|
|
2
2
|
type StatefulComponentWithState<State extends object> = TungstenStatefulComponent<any, State, any> | TungstenComponent<any, State, any>;
|
|
3
3
|
type StatefulComponentAny = TungstenStatefulComponent<any, any, any> | TungstenComponent<any, any, any>;
|
|
4
|
+
export declare const $original: unique symbol;
|
|
5
|
+
export declare const $ownerName: unique symbol;
|
|
4
6
|
export declare const getStateProxyHandler: <State extends object>(element: StatefulComponentWithState<State>) => {
|
|
5
7
|
get: (obj: State, key: string | symbol) => unknown;
|
|
6
8
|
set: (obj: State, key: string | symbol, value: unknown) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentProxyHandlers.d.ts","sourceRoot":"","sources":["../src/componentProxyHandlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"componentProxyHandlers.d.ts","sourceRoot":"","sources":["../src/componentProxyHandlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAS/E,KAAK,0BAA0B,CAAC,KAAK,SAAS,MAAM,IAC9C,yBAAyB,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,GAC1C,iBAAiB,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;AAExC,KAAK,oBAAoB,GAAG,yBAAyB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEvG,eAAO,MAAM,SAAS,eAAqB,CAAA;AAC3C,eAAO,MAAM,UAAU,eAAsB,CAAA;AAE7C,eAAO,MAAM,oBAAoB,GAAI,KAAK,SAAS,MAAM,WAC/C,0BAA0B,CAAC,KAAK,CAAC;eAC5B,KAAK,OAAO,MAAM,GAAG,MAAM;eAQ3B,KAAK,OAAO,MAAM,GAAG,MAAM,SAAS,OAAO;0BAkChC,KAAK,OAAO,MAAM,GAAG,MAAM;CAOnD,CAAA;AAGF,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,WAAW,oBAAoB;eAC3E,CAAC,OAAO,MAAM,GAAG,MAAM;eAKvB,CAAC,OAAO,MAAM,GAAG,MAAM,SAAS,OAAO;0BAgC5B,CAAC,OAAO,MAAM,GAAG,MAAM;CAO/C,CAAA;AAGF,eAAO,MAAM,yBAAyB,YAAa,oBAAoB;eACxD,OAAO,EAAE,OAAO,MAAM,GAAG,MAAM;eAwB/B,OAAO,EAAE,OAAO,MAAM,GAAG,MAAM,SAAS,OAAO;CA6B5D,CAAA;AAIF,eAAO,MAAM,uBAAuB,YAAa,oBAAoB;eACtD,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,MAAM,GAAG,MAAM;CA8CxD,CAAA;AAIF,eAAO,MAAM,uBAAuB,YAAa,oBAAoB;eACtD,GAAG,CAAC,OAAO,CAAC,OAAO,MAAM,GAAG,MAAM;CAyC/C,CAAA;AAgCF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAiCnG;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAgCpG"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { KeyIsArrayMutatingFunction, KeyIsMapMutatingFunction, KeyIsSetMutatingFunction } from "./mutatingFunctions.js";
|
|
2
2
|
import { objectTypesToProxy } from "./objectTypesToProxy.js";
|
|
3
|
-
import {
|
|
3
|
+
import { throwError } from "./throwError.js";
|
|
4
|
+
export const $original = Symbol('original');
|
|
5
|
+
export const $ownerName = Symbol('ownerName');
|
|
4
6
|
export const getStateProxyHandler = element => ({
|
|
5
7
|
get: (obj, key) => {
|
|
6
8
|
if (key === '__original') return obj; // return the internal object if requested
|
|
9
|
+
if (key === $original) return obj; // return the internal object if requested
|
|
10
|
+
// owner?
|
|
11
|
+
if (key === $ownerName) return element.constructor.name;
|
|
7
12
|
return obj[key]; // Proxy typing allowed accessing keys outside of the type.
|
|
8
13
|
// So act on that obj as an object that accept all string | symbol keys
|
|
9
14
|
},
|
|
@@ -12,19 +17,28 @@ export const getStateProxyHandler = element => ({
|
|
|
12
17
|
//const isObject = (typeof value === 'object' && value !== null)
|
|
13
18
|
if (Array.isArray(value)) {
|
|
14
19
|
// arrays
|
|
15
|
-
obj[key]
|
|
20
|
+
obj[key]
|
|
21
|
+
//= new Proxy<unknown[]>(value, getStateArrayProxyHandler(element)) // if an array was set, proxy it too
|
|
22
|
+
= proxyArray(value, element);
|
|
16
23
|
} else if (typeof value === 'object' && value !== null && objectTypesToProxy.includes(value.constructor.name) // ensure that it is an object literal or otherwise an approved object type
|
|
17
24
|
) {
|
|
18
25
|
// plain objects
|
|
19
|
-
|
|
26
|
+
// if an plian object was set, proxy it too. If an object has a class other than Object, we'll leave it alone
|
|
27
|
+
obj[key]
|
|
28
|
+
//= new Proxy(value, getStateObjectProxyHandler(element))
|
|
29
|
+
= proxyObject(value, element);
|
|
20
30
|
} else if (value instanceof Map) {
|
|
21
31
|
// Maps
|
|
22
32
|
//console.log('found a Map in state');
|
|
23
|
-
obj[key]
|
|
33
|
+
obj[key];
|
|
34
|
+
//= new Proxy(value, getStateMapProxyHandler(element))
|
|
35
|
+
proxyMap(value, element);
|
|
24
36
|
} else if (value instanceof Set) {
|
|
25
37
|
// Sets
|
|
26
38
|
//console.log('found a Set in state');
|
|
27
|
-
obj[key]
|
|
39
|
+
obj[key]
|
|
40
|
+
//= new Proxy(value, getStateSetProxyHandler(element))
|
|
41
|
+
= proxySet(value, element);
|
|
28
42
|
} else {
|
|
29
43
|
obj[key] = value;
|
|
30
44
|
}
|
|
@@ -52,20 +66,28 @@ export const getStateObjectProxyHandler = element => ({
|
|
|
52
66
|
//console.log('proxied object set')
|
|
53
67
|
if (Array.isArray(value)) {
|
|
54
68
|
// arrays
|
|
55
|
-
obj[key]
|
|
69
|
+
obj[key]
|
|
70
|
+
//= new Proxy(value, getStateArrayProxyHandler(element)) // if an array was set, proxy it too
|
|
71
|
+
= proxyArray(value, element);
|
|
56
72
|
} else if (typeof value === 'object' && value !== null
|
|
57
73
|
// && value.constructor.name === 'Object'
|
|
58
74
|
&& objectTypesToProxy.includes(value.constructor.name) // ensure that it is an object literal or otherwise an approve object type
|
|
59
75
|
) {
|
|
60
76
|
// plain objects
|
|
61
|
-
obj[key]
|
|
77
|
+
obj[key]
|
|
78
|
+
//= new Proxy(value, getStateObjectProxyHandler(element)) // if an plan object was set, proxy it too. If an object has a class other than Object, we'll leave it alone
|
|
79
|
+
= proxyObject(value, element);
|
|
62
80
|
} else if (value instanceof Map) {
|
|
63
81
|
// Maps
|
|
64
82
|
//console.log('applying a map proxy is state');
|
|
65
|
-
obj[key]
|
|
83
|
+
obj[key]
|
|
84
|
+
//= new Proxy(value, getStateMapProxyHandler(element))
|
|
85
|
+
= proxyMap(value, element);
|
|
66
86
|
} else if (value instanceof Set) {
|
|
67
87
|
// Sets
|
|
68
|
-
obj[key]
|
|
88
|
+
obj[key]
|
|
89
|
+
//= new Proxy(value, getStateSetProxyHandler(element))
|
|
90
|
+
= proxySet(value, element);
|
|
69
91
|
} else {
|
|
70
92
|
obj[key] = value;
|
|
71
93
|
}
|
|
@@ -86,6 +108,9 @@ export const getStateObjectProxyHandler = element => ({
|
|
|
86
108
|
export const getStateArrayProxyHandler = element => ({
|
|
87
109
|
get: (arr, key) => {
|
|
88
110
|
//console.log('arr key', typeof key)
|
|
111
|
+
if (key === $original) return arr; // return the internal object if requested
|
|
112
|
+
// owner?
|
|
113
|
+
if (key === $ownerName) return element.constructor.name;
|
|
89
114
|
if (typeof key === 'string') {
|
|
90
115
|
if (key === '__original') return arr; // return the internal object if requested
|
|
91
116
|
if (KeyIsArrayMutatingFunction(key)) {
|
|
@@ -110,21 +135,25 @@ export const getStateArrayProxyHandler = element => ({
|
|
|
110
135
|
if (Array.isArray(value)) {
|
|
111
136
|
// arrays
|
|
112
137
|
// @ts-ignore // TS doesn't like us accessing array by string key
|
|
113
|
-
arr[key]
|
|
138
|
+
arr[key]
|
|
139
|
+
//= new Proxy(value, getStateArrayProxyHandler as ProxyHandler<unknown[]>) // if an array was set, proxy it too
|
|
140
|
+
= proxyArray(value, element);
|
|
114
141
|
} else if (typeof value === 'object' && value !== null
|
|
115
142
|
// && value.constructor.name === 'Object'
|
|
116
143
|
&& objectTypesToProxy.includes(value.constructor.name) // ensure that it is an object literal or otherwise an approve object type
|
|
117
144
|
) {
|
|
118
145
|
// plain objects
|
|
119
146
|
// @ts-ignore // TS doesn't like us accessing array by string key
|
|
120
|
-
arr[key]
|
|
147
|
+
arr[key]
|
|
148
|
+
//= new Proxy(value, getStateObjectProxyHandler) // if an plan object was set, proxy it too. If an object has a class other than Object, we'll leave it alone
|
|
149
|
+
= proxyObject(value, element);
|
|
121
150
|
} else {
|
|
122
151
|
// @ts-ignore // TS doesn't like us accessing array by string key
|
|
123
152
|
arr[key] = value;
|
|
124
153
|
}
|
|
125
154
|
// reactivity
|
|
126
|
-
const varKey = key
|
|
127
|
-
warn('__stateArrayProxyHandler set __reactiveUpdate key may overlap between strings and numbers')
|
|
155
|
+
//const varKey = key
|
|
156
|
+
//warn('__stateArrayProxyHandler set __reactiveUpdate key may overlap between strings and numbers')
|
|
128
157
|
//this.__reactiveUpdate(String(varKey))
|
|
129
158
|
if (element.__initialized) element.__queueUpdate();
|
|
130
159
|
return true;
|
|
@@ -134,6 +163,9 @@ export const getStateArrayProxyHandler = element => ({
|
|
|
134
163
|
export const getStateMapProxyHandler = element => ({
|
|
135
164
|
get: (map, key) => {
|
|
136
165
|
//console.log('map get', key)
|
|
166
|
+
if (key === $original) return map; // return the internal object if requested
|
|
167
|
+
// owner?
|
|
168
|
+
if (key === $ownerName) return element.constructor.name;
|
|
137
169
|
if (typeof key === 'string') {
|
|
138
170
|
if (key === '__original') return map; // return the internal object if requested
|
|
139
171
|
if (KeyIsMapMutatingFunction(key)) {
|
|
@@ -176,6 +208,9 @@ export const getStateMapProxyHandler = element => ({
|
|
|
176
208
|
export const getStateSetProxyHandler = element => ({
|
|
177
209
|
get: (set, key) => {
|
|
178
210
|
//console.log('arr key', typeof key)
|
|
211
|
+
if (key === $original) return set; // return the internal object if requested
|
|
212
|
+
// owner?
|
|
213
|
+
if (key === $ownerName) return element.constructor.name;
|
|
179
214
|
if (typeof key === 'string') {
|
|
180
215
|
if (key === '__original') return set; // return the internal object if requested
|
|
181
216
|
if (KeyIsSetMutatingFunction(key)) {
|
|
@@ -245,26 +280,30 @@ export function proxyObjectContent(element, object) {
|
|
|
245
280
|
// objects, including array
|
|
246
281
|
if (Array.isArray(value)) {
|
|
247
282
|
proxyArrayContent(element, value);
|
|
248
|
-
object[key]
|
|
249
|
-
|
|
250
|
-
|
|
283
|
+
object[key]
|
|
284
|
+
//= new Proxy(value, getStateObjectProxyHandler(element))
|
|
285
|
+
= proxyArray(value, element);
|
|
251
286
|
} else if (typeof value === 'object' && value !== null
|
|
252
287
|
// && value.constructor.name === 'Object'
|
|
253
288
|
&& objectTypesToProxy.includes(value.constructor.name) // ensure that it is an object literal or otherwise an approve object type
|
|
254
289
|
) {
|
|
255
290
|
// plain objects
|
|
256
291
|
proxyObjectContent(element, value);
|
|
257
|
-
object[key]
|
|
258
|
-
|
|
259
|
-
|
|
292
|
+
object[key]
|
|
293
|
+
//= new Proxy(value, getStateObjectProxyHandler(element))
|
|
294
|
+
= proxyObject(value, element);
|
|
260
295
|
} else if (value instanceof Map) {
|
|
261
296
|
// Maps
|
|
262
297
|
//console.log('proxying a Map in state');
|
|
263
|
-
object[key]
|
|
298
|
+
object[key]
|
|
299
|
+
//= new Proxy(value, getStateMapProxyHandler(element))
|
|
300
|
+
= proxyMap(value, element);
|
|
264
301
|
} else if (value instanceof Set) {
|
|
265
302
|
// Sets
|
|
266
303
|
//console.log('proxying a Set in state');
|
|
267
|
-
object[key]
|
|
304
|
+
object[key]
|
|
305
|
+
//= new Proxy(value, getStateSetProxyHandler(element))
|
|
306
|
+
= proxySet(value, element);
|
|
268
307
|
}
|
|
269
308
|
}
|
|
270
309
|
}
|
|
@@ -276,27 +315,55 @@ export function proxyArrayContent(element, array) {
|
|
|
276
315
|
// objects, including array
|
|
277
316
|
if (Array.isArray(value)) {
|
|
278
317
|
proxyArrayContent(element, value);
|
|
279
|
-
array[key]
|
|
280
|
-
|
|
281
|
-
|
|
318
|
+
array[key]
|
|
319
|
+
//= new Proxy(value, getStateObjectProxyHandler(element))
|
|
320
|
+
= proxyArray(value, element);
|
|
282
321
|
} else if (typeof value === 'object' && value !== null
|
|
283
322
|
// && value.constructor.name === 'Object'
|
|
284
323
|
&& objectTypesToProxy.includes(value.constructor.name) // ensure that it is an object literal or otherwise an approve object type
|
|
285
324
|
) {
|
|
286
325
|
// plain objects
|
|
287
326
|
proxyObjectContent(element, value);
|
|
288
|
-
array[key]
|
|
289
|
-
|
|
290
|
-
|
|
327
|
+
array[key]
|
|
328
|
+
//= new Proxy(value, getStateObjectProxyHandler(element))
|
|
329
|
+
= proxyObject(value, element);
|
|
291
330
|
} else if (value instanceof Map) {
|
|
292
331
|
// Maps
|
|
293
332
|
//console.log('proxying a Map in state');
|
|
294
|
-
array[key]
|
|
333
|
+
array[key]
|
|
334
|
+
//= new Proxy(value, getStateMapProxyHandler(element))
|
|
335
|
+
= proxyMap(value, element);
|
|
295
336
|
} else if (value instanceof Set) {
|
|
296
337
|
// Sets
|
|
297
338
|
//console.log('proxying a Set in state');
|
|
298
|
-
array[key]
|
|
339
|
+
array[key]
|
|
340
|
+
//= new Proxy(value, getStateSetProxyHandler(element))
|
|
341
|
+
= proxySet(value, element);
|
|
299
342
|
}
|
|
300
343
|
}
|
|
301
344
|
}
|
|
345
|
+
}
|
|
346
|
+
function proxyObject(obj, element) {
|
|
347
|
+
if ($original in obj && $ownerName in obj) {
|
|
348
|
+
throwError('proxyObject', `object in ${element.constructor.name} state is already in the state of a ${obj[$ownerName]}`);
|
|
349
|
+
}
|
|
350
|
+
return new Proxy(obj, getStateObjectProxyHandler(element)); // if an plan object was set, proxy it too. If an object has a class other than Object, we'll leave it alone
|
|
351
|
+
}
|
|
352
|
+
function proxyArray(arr, element) {
|
|
353
|
+
if ($original in arr && $ownerName in arr) {
|
|
354
|
+
throwError('proxyObject', `array in ${element.constructor.name} state is already in the state of a ${arr[$ownerName]}`);
|
|
355
|
+
}
|
|
356
|
+
return new Proxy(arr, getStateArrayProxyHandler(element));
|
|
357
|
+
}
|
|
358
|
+
function proxySet(set, element) {
|
|
359
|
+
if ($original in set && $ownerName in set) {
|
|
360
|
+
throwError('proxyObject', `Set in ${element.constructor.name} state is already in the state of a ${set[$ownerName]}`);
|
|
361
|
+
}
|
|
362
|
+
return new Proxy(set, getStateSetProxyHandler(element));
|
|
363
|
+
}
|
|
364
|
+
function proxyMap(map, element) {
|
|
365
|
+
if ($original in map && $ownerName in map) {
|
|
366
|
+
throwError('proxyObject', `Map in ${element.constructor.name} state is already in the state of a ${map[$ownerName]}`);
|
|
367
|
+
}
|
|
368
|
+
return new Proxy(map, getStateMapProxyHandler(element));
|
|
302
369
|
}
|