sygnal 2.6.0 → 2.6.2
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/index.cjs.js +276 -174
- package/dist/index.esm.js +269 -167
- package/dist/sygnal.min.js +1 -1
- package/package.json +4 -1
package/dist/index.cjs.js
CHANGED
|
@@ -4,14 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var isolate = require('@cycle/isolate');
|
|
6
6
|
var state = require('@cycle/state');
|
|
7
|
-
var
|
|
7
|
+
var xstream$1 = require('xstream');
|
|
8
8
|
var run$1 = require('@cycle/run');
|
|
9
9
|
var dom = require('@cycle/dom');
|
|
10
10
|
|
|
11
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
12
|
|
|
13
13
|
var isolate__default = /*#__PURE__*/_interopDefaultLegacy(isolate);
|
|
14
|
-
var
|
|
14
|
+
var xstream__default = /*#__PURE__*/_interopDefaultLegacy(xstream$1);
|
|
15
15
|
|
|
16
16
|
function collection(component, stateLense, opts={}) {
|
|
17
17
|
const {
|
|
@@ -351,6 +351,16 @@ var hasSymbols$2 = function hasNativeSymbols() {
|
|
|
351
351
|
return hasSymbolSham();
|
|
352
352
|
};
|
|
353
353
|
|
|
354
|
+
var test = {
|
|
355
|
+
foo: {}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
var $Object = Object;
|
|
359
|
+
|
|
360
|
+
var hasProto$1 = function hasProto() {
|
|
361
|
+
return { __proto__: test }.foo === test.foo && !({ __proto__: null } instanceof $Object);
|
|
362
|
+
};
|
|
363
|
+
|
|
354
364
|
/* eslint no-invalid-this: 1 */
|
|
355
365
|
|
|
356
366
|
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
|
|
@@ -453,18 +463,23 @@ var ThrowTypeError = $gOPD
|
|
|
453
463
|
: throwTypeError;
|
|
454
464
|
|
|
455
465
|
var hasSymbols$1 = hasSymbols$2();
|
|
466
|
+
var hasProto = hasProto$1();
|
|
456
467
|
|
|
457
|
-
var getProto = Object.getPrototypeOf ||
|
|
468
|
+
var getProto = Object.getPrototypeOf || (
|
|
469
|
+
hasProto
|
|
470
|
+
? function (x) { return x.__proto__; } // eslint-disable-line no-proto
|
|
471
|
+
: null
|
|
472
|
+
);
|
|
458
473
|
|
|
459
474
|
var needsEval = {};
|
|
460
475
|
|
|
461
|
-
var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array);
|
|
476
|
+
var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined$1 : getProto(Uint8Array);
|
|
462
477
|
|
|
463
478
|
var INTRINSICS = {
|
|
464
479
|
'%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
|
|
465
480
|
'%Array%': Array,
|
|
466
481
|
'%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
|
|
467
|
-
'%ArrayIteratorPrototype%': hasSymbols$1 ? getProto([][Symbol.iterator]()) : undefined$1,
|
|
482
|
+
'%ArrayIteratorPrototype%': hasSymbols$1 && getProto ? getProto([][Symbol.iterator]()) : undefined$1,
|
|
468
483
|
'%AsyncFromSyncIteratorPrototype%': undefined$1,
|
|
469
484
|
'%AsyncFunction%': needsEval,
|
|
470
485
|
'%AsyncGenerator%': needsEval,
|
|
@@ -472,6 +487,8 @@ var INTRINSICS = {
|
|
|
472
487
|
'%AsyncIteratorPrototype%': needsEval,
|
|
473
488
|
'%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
|
|
474
489
|
'%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
|
|
490
|
+
'%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined$1 : BigInt64Array,
|
|
491
|
+
'%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined$1 : BigUint64Array,
|
|
475
492
|
'%Boolean%': Boolean,
|
|
476
493
|
'%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
|
|
477
494
|
'%Date%': Date,
|
|
@@ -492,10 +509,10 @@ var INTRINSICS = {
|
|
|
492
509
|
'%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
|
|
493
510
|
'%isFinite%': isFinite,
|
|
494
511
|
'%isNaN%': isNaN,
|
|
495
|
-
'%IteratorPrototype%': hasSymbols$1 ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
|
|
512
|
+
'%IteratorPrototype%': hasSymbols$1 && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
|
|
496
513
|
'%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
|
|
497
514
|
'%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
|
|
498
|
-
'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
|
|
515
|
+
'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
|
|
499
516
|
'%Math%': Math,
|
|
500
517
|
'%Number%': Number,
|
|
501
518
|
'%Object%': Object,
|
|
@@ -508,10 +525,10 @@ var INTRINSICS = {
|
|
|
508
525
|
'%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
|
|
509
526
|
'%RegExp%': RegExp,
|
|
510
527
|
'%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
|
|
511
|
-
'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
|
|
528
|
+
'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
|
|
512
529
|
'%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
|
|
513
530
|
'%String%': String,
|
|
514
|
-
'%StringIteratorPrototype%': hasSymbols$1 ? getProto(''[Symbol.iterator]()) : undefined$1,
|
|
531
|
+
'%StringIteratorPrototype%': hasSymbols$1 && getProto ? getProto(''[Symbol.iterator]()) : undefined$1,
|
|
515
532
|
'%Symbol%': hasSymbols$1 ? Symbol : undefined$1,
|
|
516
533
|
'%SyntaxError%': $SyntaxError,
|
|
517
534
|
'%ThrowTypeError%': ThrowTypeError,
|
|
@@ -527,6 +544,16 @@ var INTRINSICS = {
|
|
|
527
544
|
'%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
|
|
528
545
|
};
|
|
529
546
|
|
|
547
|
+
if (getProto) {
|
|
548
|
+
try {
|
|
549
|
+
null.error; // eslint-disable-line no-unused-expressions
|
|
550
|
+
} catch (e) {
|
|
551
|
+
// https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229
|
|
552
|
+
var errorProto = getProto(getProto(e));
|
|
553
|
+
INTRINSICS['%Error.prototype%'] = errorProto;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
530
557
|
var doEval = function doEval(name) {
|
|
531
558
|
var value;
|
|
532
559
|
if (name === '%AsyncFunction%') {
|
|
@@ -542,7 +569,7 @@ var doEval = function doEval(name) {
|
|
|
542
569
|
}
|
|
543
570
|
} else if (name === '%AsyncIteratorPrototype%') {
|
|
544
571
|
var gen = doEval('%AsyncGenerator%');
|
|
545
|
-
if (gen) {
|
|
572
|
+
if (gen && getProto) {
|
|
546
573
|
value = getProto(gen.prototype);
|
|
547
574
|
}
|
|
548
575
|
}
|
|
@@ -612,6 +639,7 @@ var $concat = bind.call(Function.call, Array.prototype.concat);
|
|
|
612
639
|
var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
|
|
613
640
|
var $replace = bind.call(Function.call, String.prototype.replace);
|
|
614
641
|
var $strSlice = bind.call(Function.call, String.prototype.slice);
|
|
642
|
+
var $exec = bind.call(Function.call, RegExp.prototype.exec);
|
|
615
643
|
|
|
616
644
|
/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
|
|
617
645
|
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
@@ -667,6 +695,9 @@ var getIntrinsic = function GetIntrinsic(name, allowMissing) {
|
|
|
667
695
|
throw new $TypeError('"allowMissing" argument must be a boolean');
|
|
668
696
|
}
|
|
669
697
|
|
|
698
|
+
if ($exec(/^%?[^%]*%?$/, name) === null) {
|
|
699
|
+
throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
|
|
700
|
+
}
|
|
670
701
|
var parts = stringToPath(name);
|
|
671
702
|
var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
|
|
672
703
|
|
|
@@ -787,8 +818,14 @@ var hasPropertyDescriptors = hasPropertyDescriptors_1();
|
|
|
787
818
|
var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
|
|
788
819
|
|
|
789
820
|
var defineProperty = function (object, name, value, predicate) {
|
|
790
|
-
if (name in object
|
|
791
|
-
|
|
821
|
+
if (name in object) {
|
|
822
|
+
if (predicate === true) {
|
|
823
|
+
if (object[name] === value) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
} else if (!isFunction(predicate) || !predicate()) {
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
792
829
|
}
|
|
793
830
|
if (supportsDescriptors) {
|
|
794
831
|
origDefineProperty(object, name, {
|
|
@@ -2740,11 +2777,11 @@ function switchable(factories, name$, initial, opts={}) {
|
|
|
2740
2777
|
const nameType = typeof name$;
|
|
2741
2778
|
|
|
2742
2779
|
if (!name$) throw new Error(`Missing 'name$' parameter for switchable()`)
|
|
2743
|
-
if (!(nameType === 'string' || nameType === 'function' || name$ instanceof
|
|
2780
|
+
if (!(nameType === 'string' || nameType === 'function' || name$ instanceof xstream$1.Stream)) {
|
|
2744
2781
|
throw new Error(`Invalid 'name$' parameter for switchable(): expects Stream, String, or Function`)
|
|
2745
2782
|
}
|
|
2746
2783
|
|
|
2747
|
-
if (name$ instanceof
|
|
2784
|
+
if (name$ instanceof xstream$1.Stream) {
|
|
2748
2785
|
const withInitial$ = name$
|
|
2749
2786
|
.compose(_default$5())
|
|
2750
2787
|
.startWith(initial)
|
|
@@ -2754,7 +2791,7 @@ function switchable(factories, name$, initial, opts={}) {
|
|
|
2754
2791
|
const mapFunction = (nameType === 'function' && name$) || (state => state[name$]);
|
|
2755
2792
|
return sources => {
|
|
2756
2793
|
const state$ = sources && ((typeof stateSourceName === 'string' && sources[stateSourceName]) || sources.STATE || sources.state).stream;
|
|
2757
|
-
if (!state$ instanceof
|
|
2794
|
+
if (!state$ instanceof xstream$1.Stream) throw new Error(`Could not find the state source: ${ stateSourceName }`)
|
|
2758
2795
|
const _name$ = state$
|
|
2759
2796
|
.map(mapFunction)
|
|
2760
2797
|
.filter(name => typeof name === 'string')
|
|
@@ -2786,7 +2823,7 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
2786
2823
|
.map(([name, factory]) => {
|
|
2787
2824
|
if (sources[stateSourceName]) {
|
|
2788
2825
|
const state$ = sources[stateSourceName].stream;
|
|
2789
|
-
const switched =
|
|
2826
|
+
const switched = xstream__default["default"].combine(name$, state$)
|
|
2790
2827
|
.filter(([newComponentName, _]) => newComponentName == name)
|
|
2791
2828
|
.map(([_, state]) => state)
|
|
2792
2829
|
.remember();
|
|
@@ -2803,7 +2840,7 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
2803
2840
|
obj[sinkName] = name$
|
|
2804
2841
|
.map( newComponentName => {
|
|
2805
2842
|
const sink = sinks.find(([componentName, _]) => componentName === newComponentName);
|
|
2806
|
-
return (sink && sink[1][sinkName]) ||
|
|
2843
|
+
return (sink && sink[1][sinkName]) || xstream__default["default"].never()
|
|
2807
2844
|
})
|
|
2808
2845
|
.flatten()
|
|
2809
2846
|
.remember()
|
|
@@ -2811,7 +2848,7 @@ function _switchable (factories, sources, name$, switched=['DOM'], stateSourceNa
|
|
|
2811
2848
|
} else {
|
|
2812
2849
|
const definedSinks = sinks.filter(([_,sink]) => sink[sinkName] !== undefined)
|
|
2813
2850
|
.map(([_,sink]) => sink[sinkName]);
|
|
2814
|
-
obj[sinkName] =
|
|
2851
|
+
obj[sinkName] = xstream__default["default"].merge(...definedSinks);
|
|
2815
2852
|
}
|
|
2816
2853
|
return obj
|
|
2817
2854
|
}, {});
|
|
@@ -3243,7 +3280,7 @@ class Component {
|
|
|
3243
3280
|
|
|
3244
3281
|
if (IS_ROOT_COMPONENT && typeof this.intent === 'undefined' && typeof this.model === 'undefined') {
|
|
3245
3282
|
this.initialState = initialState || true;
|
|
3246
|
-
this.intent = _ => ({__NOOP_ACTION__:
|
|
3283
|
+
this.intent = _ => ({__NOOP_ACTION__:xstream__default["default"].never()});
|
|
3247
3284
|
this.model = {
|
|
3248
3285
|
__NOOP_ACTION__: state => state
|
|
3249
3286
|
};
|
|
@@ -3275,7 +3312,7 @@ class Component {
|
|
|
3275
3312
|
|
|
3276
3313
|
this.intent$ = this.intent(this.sources);
|
|
3277
3314
|
|
|
3278
|
-
if (!(this.intent$ instanceof
|
|
3315
|
+
if (!(this.intent$ instanceof xstream$1.Stream) && (typeof this.intent$ != 'object')) {
|
|
3279
3316
|
throw new Error('Intent must return either an action$ stream or map of event streams')
|
|
3280
3317
|
}
|
|
3281
3318
|
}
|
|
@@ -3284,21 +3321,21 @@ class Component {
|
|
|
3284
3321
|
const requestSource = (this.sources && this.sources[this.requestSourceName]) || null;
|
|
3285
3322
|
|
|
3286
3323
|
if (!this.intent$) {
|
|
3287
|
-
this.action$ =
|
|
3324
|
+
this.action$ = xstream__default["default"].never();
|
|
3288
3325
|
return
|
|
3289
3326
|
}
|
|
3290
3327
|
|
|
3291
3328
|
let runner;
|
|
3292
|
-
if (this.intent$ instanceof
|
|
3329
|
+
if (this.intent$ instanceof xstream$1.Stream) {
|
|
3293
3330
|
runner = this.intent$;
|
|
3294
3331
|
} else {
|
|
3295
3332
|
const mapped = Object.entries(this.intent$)
|
|
3296
3333
|
.map(([type, data$]) => data$.map(data => ({type, data})));
|
|
3297
|
-
runner =
|
|
3334
|
+
runner = xstream__default["default"].merge(xstream__default["default"].never(), ...mapped);
|
|
3298
3335
|
}
|
|
3299
3336
|
|
|
3300
|
-
const action$ = ((runner instanceof
|
|
3301
|
-
const wrapped$ = _default$3(
|
|
3337
|
+
const action$ = ((runner instanceof xstream$1.Stream) ? runner : (runner.apply && runner(this.sources) || xstream__default["default"].never()));
|
|
3338
|
+
const wrapped$ = _default$3(xstream__default["default"].of({ type: BOOTSTRAP_ACTION }), action$)
|
|
3302
3339
|
.compose(_default$4(10));
|
|
3303
3340
|
|
|
3304
3341
|
let initialApiData;
|
|
@@ -3306,12 +3343,12 @@ class Component {
|
|
|
3306
3343
|
initialApiData = requestSource.select('initial')
|
|
3307
3344
|
.flatten();
|
|
3308
3345
|
} else {
|
|
3309
|
-
initialApiData =
|
|
3346
|
+
initialApiData = xstream__default["default"].never();
|
|
3310
3347
|
}
|
|
3311
3348
|
|
|
3312
3349
|
const hydrate$ = initialApiData.map(data => ({ type: HYDRATE_ACTION, data }));
|
|
3313
3350
|
|
|
3314
|
-
this.action$ =
|
|
3351
|
+
this.action$ = xstream__default["default"].merge(wrapped$, hydrate$)
|
|
3315
3352
|
.compose(this.log(({ type }) => `Action triggered: <${ type }>`));
|
|
3316
3353
|
}
|
|
3317
3354
|
|
|
@@ -3368,7 +3405,7 @@ class Component {
|
|
|
3368
3405
|
if (actionType === 'function') {
|
|
3369
3406
|
const enhancedState = this.addCalculated(this.currentState);
|
|
3370
3407
|
const result = action(enhancedState, req);
|
|
3371
|
-
return
|
|
3408
|
+
return xstream__default["default"].of({ ...obj, data: result })
|
|
3372
3409
|
} else {
|
|
3373
3410
|
this.action$.shamefullySendNext(obj);
|
|
3374
3411
|
|
|
@@ -3378,7 +3415,7 @@ class Component {
|
|
|
3378
3415
|
const selected$ = source[REQUEST_SELECTOR_METHOD](_reqId);
|
|
3379
3416
|
return [ ...acc, selected$ ]
|
|
3380
3417
|
}, []);
|
|
3381
|
-
return
|
|
3418
|
+
return xstream__default["default"].merge(...responses)
|
|
3382
3419
|
}
|
|
3383
3420
|
} catch(err) {
|
|
3384
3421
|
console.error(err);
|
|
@@ -3386,11 +3423,11 @@ class Component {
|
|
|
3386
3423
|
}).flatten();
|
|
3387
3424
|
return [ ...acc, route$ ]
|
|
3388
3425
|
}, []);
|
|
3389
|
-
const mapped$ =
|
|
3426
|
+
const mapped$ = xstream__default["default"].merge(...mapped);
|
|
3390
3427
|
return [ ...acc, mapped$ ]
|
|
3391
3428
|
}, []);
|
|
3392
3429
|
|
|
3393
|
-
this.response$ =
|
|
3430
|
+
this.response$ = xstream__default["default"].merge(...wrapped)
|
|
3394
3431
|
.compose(this.log(res => {
|
|
3395
3432
|
if (res._action) return `[${ this.requestSourceName }] response data received for Action: <${ res._action }>`
|
|
3396
3433
|
return `[${ this.requestSourceName }] response data received from FUNCTION`
|
|
@@ -3421,14 +3458,14 @@ class Component {
|
|
|
3421
3458
|
initModel$() {
|
|
3422
3459
|
if (typeof this.model == 'undefined') {
|
|
3423
3460
|
this.model$ = this.sourceNames.reduce((a,s) => {
|
|
3424
|
-
a[s] =
|
|
3461
|
+
a[s] = xstream__default["default"].never();
|
|
3425
3462
|
return a
|
|
3426
3463
|
}, {});
|
|
3427
3464
|
return
|
|
3428
3465
|
}
|
|
3429
3466
|
|
|
3430
3467
|
const initial = { type: INITIALIZE_ACTION, data: this.initialState };
|
|
3431
|
-
const shimmed$ = this.initialState ? _default$3(
|
|
3468
|
+
const shimmed$ = this.initialState ? _default$3(xstream__default["default"].of(initial), this.action$).compose(_default$4(0)) : this.action$;
|
|
3432
3469
|
const onState = this.makeOnAction(shimmed$, true, this.action$);
|
|
3433
3470
|
const onNormal = this.makeOnAction(this.action$, false, this.action$);
|
|
3434
3471
|
|
|
@@ -3477,7 +3514,7 @@ class Component {
|
|
|
3477
3514
|
|
|
3478
3515
|
const model$ = Object.entries(reducers).reduce((acc, entry) => {
|
|
3479
3516
|
const [sink, streams] = entry;
|
|
3480
|
-
acc[sink] =
|
|
3517
|
+
acc[sink] = xstream__default["default"].merge(xstream__default["default"].never(), ...streams);
|
|
3481
3518
|
return acc
|
|
3482
3519
|
}, {});
|
|
3483
3520
|
|
|
@@ -3496,7 +3533,7 @@ class Component {
|
|
|
3496
3533
|
next: this.log(({ _reqId, _action }) => `Unhandled response for request: ${ _action } ${ _reqId }`)
|
|
3497
3534
|
});
|
|
3498
3535
|
}
|
|
3499
|
-
this.sendResponse$ =
|
|
3536
|
+
this.sendResponse$ = xstream__default["default"].never();
|
|
3500
3537
|
return
|
|
3501
3538
|
}
|
|
3502
3539
|
|
|
@@ -3524,7 +3561,7 @@ class Component {
|
|
|
3524
3561
|
return [ ...acc, mapped$ ]
|
|
3525
3562
|
}, []);
|
|
3526
3563
|
|
|
3527
|
-
this.sendResponse$ =
|
|
3564
|
+
this.sendResponse$ = xstream__default["default"].merge(...out$)
|
|
3528
3565
|
.compose(this.log(({ _reqId, _action }) => `[${ this.requestSourceName }] response sent for: <${ _action }>`));
|
|
3529
3566
|
}
|
|
3530
3567
|
|
|
@@ -3552,7 +3589,7 @@ class Component {
|
|
|
3552
3589
|
}
|
|
3553
3590
|
|
|
3554
3591
|
initSubComponentSink$() {
|
|
3555
|
-
const subComponentSink$ =
|
|
3592
|
+
const subComponentSink$ = xstream__default["default"].create({
|
|
3556
3593
|
start: listener => {
|
|
3557
3594
|
this.newSubComponentSinks = listener.next.bind(listener);
|
|
3558
3595
|
},
|
|
@@ -3565,7 +3602,7 @@ class Component {
|
|
|
3565
3602
|
}
|
|
3566
3603
|
|
|
3567
3604
|
initSubComponentsRendered$() {
|
|
3568
|
-
const stream =
|
|
3605
|
+
const stream = xstream__default["default"].create({
|
|
3569
3606
|
start: (listener) => {
|
|
3570
3607
|
this.subComponentsRendered = listener.next.bind(listener);
|
|
3571
3608
|
},
|
|
@@ -3578,7 +3615,7 @@ class Component {
|
|
|
3578
3615
|
|
|
3579
3616
|
initVdom$() {
|
|
3580
3617
|
if (typeof this.view != 'function') {
|
|
3581
|
-
this.vdom$ =
|
|
3618
|
+
this.vdom$ = xstream__default["default"].of(null);
|
|
3582
3619
|
return
|
|
3583
3620
|
}
|
|
3584
3621
|
|
|
@@ -3596,17 +3633,17 @@ class Component {
|
|
|
3596
3633
|
initSinks() {
|
|
3597
3634
|
this.sinks = this.sourceNames.reduce((acc, name) => {
|
|
3598
3635
|
if (name == this.DOMSourceName) return acc
|
|
3599
|
-
const subComponentSink$ = this.subComponentSink$ ? this.subComponentSink$.map(sinks => sinks[name]).filter(sink => !!sink).flatten() :
|
|
3636
|
+
const subComponentSink$ = this.subComponentSink$ ? this.subComponentSink$.map(sinks => sinks[name]).filter(sink => !!sink).flatten() : xstream__default["default"].never();
|
|
3600
3637
|
if (name === this.stateSourceName) {
|
|
3601
|
-
acc[name] =
|
|
3638
|
+
acc[name] = xstream__default["default"].merge((this.model$[name] || xstream__default["default"].never()), subComponentSink$, this.sources[this.stateSourceName].stream.filter(_ => false), ...this.children$[name]);
|
|
3602
3639
|
} else {
|
|
3603
|
-
acc[name] =
|
|
3640
|
+
acc[name] = xstream__default["default"].merge((this.model$[name] || xstream__default["default"].never()), subComponentSink$, ...this.children$[name]);
|
|
3604
3641
|
}
|
|
3605
3642
|
return acc
|
|
3606
3643
|
}, {});
|
|
3607
3644
|
|
|
3608
3645
|
this.sinks[this.DOMSourceName] = this.vdom$;
|
|
3609
|
-
this.sinks[this.requestSourceName] =
|
|
3646
|
+
this.sinks[this.requestSourceName] = xstream__default["default"].merge(this.sendResponse$ ,this.sinks[this.requestSourceName]);
|
|
3610
3647
|
}
|
|
3611
3648
|
|
|
3612
3649
|
makeOnAction(action$, isStateSink=true, rootAction$) {
|
|
@@ -3663,7 +3700,7 @@ class Component {
|
|
|
3663
3700
|
}
|
|
3664
3701
|
|
|
3665
3702
|
addCalculated(state) {
|
|
3666
|
-
if (!this.calculated || typeof state !== 'object') return state
|
|
3703
|
+
if (!this.calculated || typeof state !== 'object' || state instanceof Array) return state
|
|
3667
3704
|
if (typeof this.calculated !== 'object') throw new Error(`'calculated' parameter must be an object mapping calculated state field named to functions`)
|
|
3668
3705
|
const entries = Object.entries(this.calculated);
|
|
3669
3706
|
const calculated = entries.reduce((acc, [field, fn]) => {
|
|
@@ -3678,11 +3715,13 @@ class Component {
|
|
|
3678
3715
|
return { ...state, ...calculated }
|
|
3679
3716
|
}
|
|
3680
3717
|
|
|
3681
|
-
cleanupCalculated(
|
|
3682
|
-
if (
|
|
3683
|
-
|
|
3718
|
+
cleanupCalculated(incomingState) {
|
|
3719
|
+
if (!incomingState || typeof incomingState !== 'object' || incomingState instanceof Array) return incomingState
|
|
3720
|
+
const state = this.storeCalculatedInState ? this.addCalculated(incomingState) : incomingState;
|
|
3721
|
+
const { __props, __children, ...sanitized } = state;
|
|
3722
|
+
const copy = { ...sanitized };
|
|
3723
|
+
if (!this.calculated) return copy
|
|
3684
3724
|
const keys = Object.keys(this.calculated);
|
|
3685
|
-
const copy = { ...state };
|
|
3686
3725
|
keys.forEach(key => {
|
|
3687
3726
|
if (this.initialState && typeof this.initialState[key] !== 'undefined') {
|
|
3688
3727
|
copy[key] = this.initialState[key];
|
|
@@ -3698,17 +3737,17 @@ class Component {
|
|
|
3698
3737
|
const renderParams = { ...this.children$[this.DOMSourceName] };
|
|
3699
3738
|
|
|
3700
3739
|
const enhancedState = state && state.isolateSource(state, { get: state => this.addCalculated(state) });
|
|
3701
|
-
const stateStream = (enhancedState && enhancedState.stream) ||
|
|
3740
|
+
const stateStream = (enhancedState && enhancedState.stream) || xstream__default["default"].never();
|
|
3702
3741
|
|
|
3703
3742
|
renderParams.state = stateStream;
|
|
3704
3743
|
renderParams[this.stateSourceName] = stateStream;
|
|
3705
3744
|
|
|
3706
3745
|
if (this.sources.props$) {
|
|
3707
|
-
renderParams.
|
|
3746
|
+
renderParams.__props = this.sources.props$;
|
|
3708
3747
|
}
|
|
3709
3748
|
|
|
3710
3749
|
if (this.sources.children$) {
|
|
3711
|
-
renderParams.
|
|
3750
|
+
renderParams.__children = this.sources.children$;
|
|
3712
3751
|
}
|
|
3713
3752
|
|
|
3714
3753
|
const names = [];
|
|
@@ -3719,7 +3758,7 @@ class Component {
|
|
|
3719
3758
|
streams.push(stream);
|
|
3720
3759
|
});
|
|
3721
3760
|
|
|
3722
|
-
const combined =
|
|
3761
|
+
const combined = xstream__default["default"].combine(...streams)
|
|
3723
3762
|
// map the streams from an array back to an object with the render parameter names as the keys
|
|
3724
3763
|
.map(arr => {
|
|
3725
3764
|
return names.reduce((acc, name, index) => {
|
|
@@ -3761,8 +3800,8 @@ class Component {
|
|
|
3761
3800
|
return acc
|
|
3762
3801
|
}
|
|
3763
3802
|
|
|
3764
|
-
const props$ =
|
|
3765
|
-
const children$ =
|
|
3803
|
+
const props$ = xstream__default["default"].create().startWith(props);
|
|
3804
|
+
const children$ = xstream__default["default"].create().startWith(children);
|
|
3766
3805
|
|
|
3767
3806
|
let instantiator;
|
|
3768
3807
|
|
|
@@ -3774,17 +3813,9 @@ class Component {
|
|
|
3774
3813
|
instantiator = this.instantiateCustomComponent.bind(this);
|
|
3775
3814
|
}
|
|
3776
3815
|
|
|
3777
|
-
const
|
|
3778
|
-
|
|
3779
|
-
if (preventStateUpdates) {
|
|
3780
|
-
const originalStateSink = sink$[this.stateSourceName];
|
|
3781
|
-
sink$[this.stateSourceName] = originalStateSink.filter(state => {
|
|
3782
|
-
console.warn('State update attempt from component with inderect link to state: Components with state set through HTML properties/attributes cannot update application state directly');
|
|
3783
|
-
return false
|
|
3784
|
-
});
|
|
3785
|
-
}
|
|
3816
|
+
const sink$ = instantiator(el, props$, children$);
|
|
3786
3817
|
|
|
3787
|
-
sink$[this.DOMSourceName] = this.makeCoordinatedSubComponentDomSink(sink$[this.DOMSourceName]);
|
|
3818
|
+
sink$[this.DOMSourceName] = sink$[this.DOMSourceName] ? this.makeCoordinatedSubComponentDomSink(sink$[this.DOMSourceName]) : xstream__default["default"].never();
|
|
3788
3819
|
|
|
3789
3820
|
acc[id] = { sink$, props$, children$ };
|
|
3790
3821
|
|
|
@@ -3798,7 +3829,7 @@ class Component {
|
|
|
3798
3829
|
|
|
3799
3830
|
const mergedSinksByType = Object.entries(sinkArrsByType).reduce((acc, [name, streamArr]) => {
|
|
3800
3831
|
if (streamArr.length === 0) return acc
|
|
3801
|
-
acc[name] = streamArr.length === 1 ? streamArr[0] :
|
|
3832
|
+
acc[name] = streamArr.length === 1 ? streamArr[0] : xstream__default["default"].merge(...streamArr);
|
|
3802
3833
|
return acc
|
|
3803
3834
|
}, {});
|
|
3804
3835
|
|
|
@@ -3827,115 +3858,160 @@ class Component {
|
|
|
3827
3858
|
const data = el.data;
|
|
3828
3859
|
const props = data.props || {};
|
|
3829
3860
|
el.children || [];
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3861
|
+
|
|
3862
|
+
const combined$ = xstream__default["default"].combine(this.sources[this.stateSourceName].stream.startWith(this.currentState), props$, children$)
|
|
3863
|
+
.map(([state, __props, __children]) => {
|
|
3864
|
+
return typeof state === 'object' ? { ...this.addCalculated(state), __props, __children } : { value: state, __props, __children }
|
|
3865
|
+
});
|
|
3866
|
+
|
|
3867
|
+
const stateSource = new state.StateSource(combined$);
|
|
3868
|
+
const stateField = props.from;
|
|
3869
|
+
let lense;
|
|
3870
|
+
|
|
3871
|
+
const factory = typeof props.of === 'function' ? props.of : this.components[props.of];
|
|
3872
|
+
|
|
3873
|
+
const sanitizeItems = item => {
|
|
3874
|
+
if (typeof item === 'object') {
|
|
3875
|
+
const { __props, __children, ...sanitized } = item;
|
|
3876
|
+
return sanitized
|
|
3877
|
+
} else {
|
|
3878
|
+
return item
|
|
3879
|
+
}
|
|
3880
|
+
};
|
|
3881
|
+
|
|
3882
|
+
const fieldLense = {
|
|
3883
|
+
get: state => {
|
|
3884
|
+
const { __props, __children } = state;
|
|
3885
|
+
if (!Array.isArray(state[stateField])) return []
|
|
3886
|
+
return state[stateField].map(item => {
|
|
3887
|
+
return typeof item === 'object' ? { ...item, __props, __children } : { value: item, __props, __children }
|
|
3888
|
+
})
|
|
3889
|
+
},
|
|
3890
|
+
set: (oldState, newState) => {
|
|
3891
|
+
if (this.calculated && stateField in this.calculated) {
|
|
3892
|
+
console.warn(`Collection sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
|
|
3893
|
+
return oldState
|
|
3894
|
+
}
|
|
3895
|
+
return { ...oldState, [stateField]: newState.map(sanitizeItems) }
|
|
3842
3896
|
}
|
|
3843
|
-
return arr
|
|
3844
3897
|
};
|
|
3845
3898
|
|
|
3846
|
-
if (
|
|
3899
|
+
if (stateField === undefined) {
|
|
3847
3900
|
lense = {
|
|
3848
3901
|
get: state => {
|
|
3849
|
-
if (!Array.
|
|
3850
|
-
console.warn(`Collection sub-component of ${ this.name } has no 'for' attribute and the parent state is not an array: Provide a 'for' attribute with either an array or the name of a state property containing an array`);
|
|
3851
|
-
return []
|
|
3852
|
-
}
|
|
3902
|
+
if (!(state instanceof Array) && state.value && state.value instanceof Array) return state.value
|
|
3853
3903
|
return state
|
|
3854
3904
|
},
|
|
3855
|
-
set: (oldState, newState) =>
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
field = props.for;
|
|
3859
|
-
lense = {
|
|
3860
|
-
get: stateGetter,
|
|
3861
|
-
set: (state, arr) => {
|
|
3862
|
-
if (this.calculated && field in this.calculated) {
|
|
3863
|
-
console.warn(`Collection sub-component of ${ this.name } attempted to update state on a calculated field '${ field }': Update ignored`);
|
|
3864
|
-
return state
|
|
3865
|
-
}
|
|
3866
|
-
return { ...state, [field]: arr }
|
|
3905
|
+
set: (oldState, newState) => {
|
|
3906
|
+
console.log('COLL SET', newState);
|
|
3907
|
+
return newState
|
|
3867
3908
|
}
|
|
3868
3909
|
};
|
|
3910
|
+
} else if (typeof stateField === 'string') {
|
|
3911
|
+
if (typeof this.currentState === 'object') {
|
|
3912
|
+
if(!(stateField in this.currentState) && !(stateField in this.calculated)) {
|
|
3913
|
+
console.error(`Collection component in ${ this.name } is attempting to use non-existent state property '${ stateField }': To fix this error, specify a valid array property on the state. Attempting to use parent component state.`);
|
|
3914
|
+
lense = undefined;
|
|
3915
|
+
} else if (!Array.isArray(this.currentState[stateField])) {
|
|
3916
|
+
console.warn(`State property '${ stateField }' in collection comopnent of ${ this.name } is not an array: No components will be instantiated in the collection.`);
|
|
3917
|
+
lense = fieldLense;
|
|
3918
|
+
} else {
|
|
3919
|
+
lense = fieldLense;
|
|
3920
|
+
}
|
|
3921
|
+
} else {
|
|
3922
|
+
if (!Array.isArray(this.currentState[stateField])) {
|
|
3923
|
+
console.warn(`State property '${ stateField }' in collection component of ${ this.name } is not an array: No components will be instantiated in the collection.`);
|
|
3924
|
+
lense = fieldLense;
|
|
3925
|
+
} else {
|
|
3926
|
+
lense = fieldLense;
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
} else if (typeof stateField === 'object') {
|
|
3930
|
+
if (typeof stateField.get !== 'function') {
|
|
3931
|
+
console.error(`Collection component in ${ this.name } has an invalid 'from' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting child state from the current state. Attempting to use parent component state.`);
|
|
3932
|
+
lense = undefined;
|
|
3933
|
+
} else {
|
|
3934
|
+
lense = { get: stateField.get, set: stateField.set };
|
|
3935
|
+
}
|
|
3869
3936
|
} else {
|
|
3870
|
-
field
|
|
3871
|
-
|
|
3872
|
-
lense = {
|
|
3873
|
-
get: stateGetter,
|
|
3874
|
-
set: (state, arr) => state
|
|
3875
|
-
};
|
|
3876
|
-
preventStateUpdates = true;
|
|
3937
|
+
console.error(`Collection component in ${ this.name } has an invalid 'from' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting child state from the current state. Attempting to use parent component state.`);
|
|
3938
|
+
lense = undefined;
|
|
3877
3939
|
}
|
|
3878
|
-
|
|
3879
|
-
const
|
|
3880
|
-
sink$
|
|
3940
|
+
|
|
3941
|
+
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
3942
|
+
const sink$ = collection(factory, lense, { container: null })(sources);
|
|
3881
3943
|
if (typeof sink$ !== 'object') {
|
|
3882
3944
|
throw new Error('Invalid sinks returned from component factory of collection element')
|
|
3883
3945
|
}
|
|
3884
|
-
return
|
|
3946
|
+
return sink$
|
|
3885
3947
|
}
|
|
3886
3948
|
|
|
3887
3949
|
instantiateSwitchable(el, props$, children$) {
|
|
3888
3950
|
const data = el.data;
|
|
3889
3951
|
const props = data.props || {};
|
|
3890
3952
|
el.children || [];
|
|
3891
|
-
let stateSource = new state.StateSource(this.sources[this.stateSourceName].stream.startWith(this.currentState));
|
|
3892
3953
|
|
|
3893
|
-
const
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3954
|
+
const combined$ = xstream__default["default"].combine(this.sources[this.stateSourceName].stream.startWith(this.currentState), props$, children$)
|
|
3955
|
+
.map(([state, __props, __children]) => {
|
|
3956
|
+
return typeof state === 'object' ? { ...this.addCalculated(state), __props, __children } : { value: state, __props, __children }
|
|
3957
|
+
});
|
|
3897
3958
|
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3959
|
+
const stateSource = new state.StateSource(combined$);
|
|
3960
|
+
const stateField = props.state;
|
|
3961
|
+
let lense;
|
|
3962
|
+
|
|
3963
|
+
const fieldLense = {
|
|
3964
|
+
get: state => {
|
|
3965
|
+
const { __props, __children } = state;
|
|
3966
|
+
return (typeof state[stateField] === 'object' && !(state[stateField] instanceof Array)) ? { ...state[stateField], __props, __children } : { value: state[stateField], __props, __children }
|
|
3967
|
+
},
|
|
3968
|
+
set: (oldState, newState) => {
|
|
3969
|
+
if (this.calculated && stateField in this.calculated) {
|
|
3970
|
+
console.warn(`Switchable sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
|
|
3971
|
+
return oldState
|
|
3910
3972
|
}
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3973
|
+
console.log('SWITCH SET', newState);
|
|
3974
|
+
if (typeof newState !== 'object' || newState instanceof Array) return { ...oldState, [stateField]: newState }
|
|
3975
|
+
const { __props, __children, ...sanitized } = newState;
|
|
3976
|
+
return { ...oldState, [stateField]: sanitized }
|
|
3977
|
+
}
|
|
3978
|
+
};
|
|
3979
|
+
|
|
3980
|
+
const baseLense = {
|
|
3981
|
+
get: state => state,
|
|
3982
|
+
set: (oldState, newState) => {
|
|
3983
|
+
if (typeof newState !== 'object' || newState instanceof Array) return newState
|
|
3984
|
+
const { __props, __children, ...sanitized } = newState;
|
|
3985
|
+
return sanitized
|
|
3986
|
+
}
|
|
3987
|
+
};
|
|
3988
|
+
|
|
3989
|
+
if (typeof stateField === 'undefined') {
|
|
3990
|
+
lense = baseLense;
|
|
3991
|
+
} else if (typeof stateField === 'string') {
|
|
3992
|
+
lense = fieldLense;
|
|
3920
3993
|
} else if (typeof stateField === 'object') {
|
|
3921
|
-
|
|
3994
|
+
if (typeof stateField.get !== 'function') {
|
|
3995
|
+
console.error(`Switchable component in ${ this.name } has an invalid 'state' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting sub-component state from the current state. Attempting to use parent component state.`);
|
|
3996
|
+
lense = baseLense;
|
|
3997
|
+
} else {
|
|
3998
|
+
lense = { get: stateField.get, set: stateField.set };
|
|
3999
|
+
}
|
|
3922
4000
|
} else {
|
|
3923
|
-
|
|
4001
|
+
console.error(`Invalid state provided to switchable sub-component of ${ this.name }: Expecting string, object, or undefined, but found ${ typeof stateField }. Attempting to use parent component state.`);
|
|
4002
|
+
lense = baseLense;
|
|
3924
4003
|
}
|
|
3925
4004
|
|
|
3926
|
-
const switchableComponents =
|
|
4005
|
+
const switchableComponents = props.of;
|
|
3927
4006
|
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
} else {
|
|
3931
|
-
sink$ = switchable(switchableComponents, props$.map(props => props.current))(sources);
|
|
3932
|
-
}
|
|
4007
|
+
|
|
4008
|
+
const sink$ = isolate__default["default"](switchable(switchableComponents, props$.map(props => props.current)), { [this.stateSourceName]: lense })(sources);
|
|
3933
4009
|
|
|
3934
4010
|
if (typeof sink$ !== 'object') {
|
|
3935
4011
|
throw new Error('Invalid sinks returned from component factory of switchable element')
|
|
3936
4012
|
}
|
|
3937
4013
|
|
|
3938
|
-
return
|
|
4014
|
+
return sink$
|
|
3939
4015
|
}
|
|
3940
4016
|
|
|
3941
4017
|
instantiateCustomComponent(el, props$, children$) {
|
|
@@ -3943,47 +4019,75 @@ class Component {
|
|
|
3943
4019
|
const data = el.data;
|
|
3944
4020
|
const props = data.props || {};
|
|
3945
4021
|
el.children || [];
|
|
3946
|
-
|
|
4022
|
+
|
|
4023
|
+
const combined$ = xstream__default["default"].combine(this.sources[this.stateSourceName].stream.startWith(this.currentState), props$, children$)
|
|
4024
|
+
.map(([state, __props, __children]) => {
|
|
4025
|
+
return typeof state === 'object' ? { ...this.addCalculated(state), __props, __children } : { value: state, __props, __children }
|
|
4026
|
+
});
|
|
4027
|
+
|
|
4028
|
+
const stateSource = new state.StateSource(combined$);
|
|
4029
|
+
const stateField = props.state;
|
|
3947
4030
|
|
|
3948
4031
|
const factory = componentName === 'sygnal-factory' ? props.sygnalFactory : (this.components[componentName] || props.sygnalFactory);
|
|
3949
|
-
if (!factory
|
|
4032
|
+
if (!factory) {
|
|
3950
4033
|
if (componentName === 'sygnal-factory') throw new Error(`Component not found on element with Capitalized selector and nameless function: JSX transpilation replaces selectors starting with upper case letters with functions in-scope with the same name, Sygnal cannot see the name of the resulting component.`)
|
|
3951
4034
|
throw new Error(`Component not found: ${ componentName }`)
|
|
3952
4035
|
}
|
|
3953
4036
|
|
|
3954
|
-
let
|
|
3955
|
-
let sink$;
|
|
4037
|
+
let lense;
|
|
3956
4038
|
|
|
3957
|
-
const
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
4039
|
+
const fieldLense = {
|
|
4040
|
+
get: state => {
|
|
4041
|
+
const { __props, __children } = state;
|
|
4042
|
+
return typeof state[stateField] === 'object' ? { ...state[stateField], __props, __children } : { value: state[stateField], __props, __children }
|
|
4043
|
+
},
|
|
4044
|
+
set: (oldState, newState) => {
|
|
4045
|
+
if (this.calculated && stateField in this.calculated) {
|
|
4046
|
+
console.warn(`Sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
|
|
4047
|
+
return oldState
|
|
4048
|
+
}
|
|
4049
|
+
return { ...oldState, [stateField]: newState }
|
|
4050
|
+
}
|
|
4051
|
+
};
|
|
4052
|
+
|
|
4053
|
+
const baseLense = {
|
|
4054
|
+
get: state => state,
|
|
4055
|
+
set: (oldState, newState) => {
|
|
4056
|
+
if (typeof newState !== 'object' || newState instanceof Array) return newState
|
|
4057
|
+
const { __props, __children, ...sanitized } = newState;
|
|
4058
|
+
return sanitized
|
|
4059
|
+
}
|
|
4060
|
+
};
|
|
4061
|
+
|
|
4062
|
+
if (typeof stateField === 'undefined') {
|
|
4063
|
+
lense = baseLense;
|
|
4064
|
+
} else if (typeof stateField === 'string') {
|
|
4065
|
+
lense = fieldLense;
|
|
4066
|
+
} else if (typeof stateField === 'object') {
|
|
4067
|
+
if (typeof stateField.get !== 'function') {
|
|
4068
|
+
console.error(`Sub-component in ${ this.name } has an invalid 'state' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting sub-component state from the current state. Attempting to use parent component state.`);
|
|
4069
|
+
lense = baseLense;
|
|
4070
|
+
} else {
|
|
4071
|
+
lense = { get: stateField.get, set: stateField.set };
|
|
4072
|
+
}
|
|
3962
4073
|
} else {
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
if (typeof state === 'undefined') return props
|
|
3966
|
-
if (typeof state !== 'object') return state
|
|
3967
|
-
|
|
3968
|
-
const copy = { ...props };
|
|
3969
|
-
delete copy.state;
|
|
3970
|
-
return { ...copy, ...state }
|
|
3971
|
-
};
|
|
3972
|
-
stateSource = new state.StateSource(props$.map(lense));
|
|
3973
|
-
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
3974
|
-
sink$ = factory(sources);
|
|
4074
|
+
console.error(`Invalid state provided to sub-component of ${ this.name }: Expecting string, object, or undefined, but found ${ typeof stateField }. Attempting to use parent component state.`);
|
|
4075
|
+
lense = baseLense;
|
|
3975
4076
|
}
|
|
3976
4077
|
|
|
4078
|
+
const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$ };
|
|
4079
|
+
const sink$ = isolate__default["default"](factory, { [this.stateSourceName]: lense })(sources);
|
|
4080
|
+
|
|
3977
4081
|
if (typeof sink$ !== 'object') {
|
|
3978
4082
|
const name = componentName === 'sygnal-factory' ? 'custom element' : componentName;
|
|
3979
4083
|
throw new Error('Invalid sinks returned from component factory:', name)
|
|
3980
4084
|
}
|
|
3981
4085
|
|
|
3982
|
-
return
|
|
4086
|
+
return sink$
|
|
3983
4087
|
}
|
|
3984
4088
|
|
|
3985
4089
|
renderVdom(componentInstances$) {
|
|
3986
|
-
return
|
|
4090
|
+
return xstream__default["default"].combine(this.subComponentsRendered$, componentInstances$)
|
|
3987
4091
|
.compose(_default$2(5))
|
|
3988
4092
|
.map(([_, components]) => {
|
|
3989
4093
|
const componentNames = Object.keys(this.components);
|
|
@@ -3992,7 +4096,7 @@ class Component {
|
|
|
3992
4096
|
const entries = Object.entries(components).filter(([id]) => id !== '::ROOT::');
|
|
3993
4097
|
|
|
3994
4098
|
if (entries.length === 0) {
|
|
3995
|
-
return
|
|
4099
|
+
return xstream__default["default"].of(root)
|
|
3996
4100
|
}
|
|
3997
4101
|
|
|
3998
4102
|
const ids = [];
|
|
@@ -4002,9 +4106,9 @@ class Component {
|
|
|
4002
4106
|
return val.sink$[this.DOMSourceName].startWith(undefined)
|
|
4003
4107
|
});
|
|
4004
4108
|
|
|
4005
|
-
if (vdom$.length === 0) return
|
|
4109
|
+
if (vdom$.length === 0) return xstream__default["default"].of(root)
|
|
4006
4110
|
|
|
4007
|
-
return
|
|
4111
|
+
return xstream__default["default"].combine(...vdom$)
|
|
4008
4112
|
.compose(_default$2(10))
|
|
4009
4113
|
.map(vdoms => {
|
|
4010
4114
|
const withIds = vdoms.reduce((acc, vdom, index) => {
|
|
@@ -4068,7 +4172,7 @@ function getComponents(currentElement, componentNames, depth=0, index=0) {
|
|
|
4068
4172
|
const isSwitchable = sel && sel.toLowerCase() === 'switchable';
|
|
4069
4173
|
const isComponent = sel && (['collection', 'switchable', 'sygnal-factory', ...componentNames].includes(currentElement.sel)) || typeof currentElement.data?.props?.sygnalFactory === 'function';
|
|
4070
4174
|
const props = (currentElement.data && currentElement.data.props) || {};
|
|
4071
|
-
|
|
4175
|
+
(currentElement.data && currentElement.data.attrs) || {};
|
|
4072
4176
|
const children = currentElement.children || [];
|
|
4073
4177
|
|
|
4074
4178
|
let found = {};
|
|
@@ -4079,11 +4183,9 @@ function getComponents(currentElement, componentNames, depth=0, index=0) {
|
|
|
4079
4183
|
if (!props.of) throw new Error(`Collection element missing required 'component' property`)
|
|
4080
4184
|
if (typeof props.of !== 'string' && typeof props.of !== 'function') throw new Error(`Invalid 'component' property of collection element: found ${ typeof props.of } requires string or component factory function`)
|
|
4081
4185
|
if (typeof props.of !== 'function' && !componentNames.includes(props.of)) throw new Error(`Specified component for collection not found: ${ props.of }`)
|
|
4082
|
-
if (typeof
|
|
4186
|
+
if (typeof props.from !== 'undefined' && !(typeof props.from === 'string' || Array.isArray(props.from))) console.warn(`No valid array found in the 'value' property of collection ${ typeof props.of === 'string' ? props.of : 'function component' }: no collection components will be created`);
|
|
4083
4187
|
currentElement.data.isCollection = true;
|
|
4084
4188
|
currentElement.data.props ||= {};
|
|
4085
|
-
currentElement.data.props.for = attrs.for;
|
|
4086
|
-
currentElement.data.attrs = undefined;
|
|
4087
4189
|
} else if (isSwitchable) {
|
|
4088
4190
|
if (!props.of) throw new Error(`Switchable element missing required 'of' property`)
|
|
4089
4191
|
if (typeof props.of !== 'object') throw new Error(`Invalid 'components' property of switchable element: found ${ typeof props.of } requires object mapping names to component factories`)
|
|
@@ -4170,7 +4272,7 @@ function processForm(form, options={}) {
|
|
|
4170
4272
|
|
|
4171
4273
|
const eventStream$ = events.map(event => form.events(event));
|
|
4172
4274
|
|
|
4173
|
-
const merged$ =
|
|
4275
|
+
const merged$ = xstream__default["default"].merge(...eventStream$);
|
|
4174
4276
|
|
|
4175
4277
|
return merged$.map((e) => {
|
|
4176
4278
|
if (preventDefault) e.preventDefault();
|
|
@@ -4231,7 +4333,7 @@ function eventBusDriver(out$) {
|
|
|
4231
4333
|
const all = !type;
|
|
4232
4334
|
const _type = (Array.isArray(type)) ? type : [type];
|
|
4233
4335
|
let cb;
|
|
4234
|
-
const in$ =
|
|
4336
|
+
const in$ = xstream__default["default"].create({
|
|
4235
4337
|
start: (listener) => {
|
|
4236
4338
|
cb = ({detail: event}) => {
|
|
4237
4339
|
const data = (event && event.data) || null;
|
|
@@ -4638,7 +4740,7 @@ var _default = sampleCombine$1.default = sampleCombine;
|
|
|
4638
4740
|
|
|
4639
4741
|
Object.defineProperty(exports, 'xs', {
|
|
4640
4742
|
enumerable: true,
|
|
4641
|
-
get: function () { return
|
|
4743
|
+
get: function () { return xstream__default["default"]; }
|
|
4642
4744
|
});
|
|
4643
4745
|
exports.ABORT = ABORT;
|
|
4644
4746
|
exports.classes = classes;
|