sygnal 2.4.0 → 2.5.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.
@@ -1,148 +0,0 @@
1
- 'use strict';
2
-
3
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
-
5
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
-
13
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
-
15
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
-
17
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
18
-
19
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
-
21
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
-
23
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
24
-
25
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
26
-
27
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
28
-
29
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
30
-
31
- import { default as xs, Stream } from 'xstream';
32
- import dropRepeats from 'xstream/extra/dropRepeats';
33
- export default function switchable(factories, name$, initial) {
34
- var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
35
- var _opts$switched = opts.switched,
36
- switched = _opts$switched === void 0 ? ['DOM'] : _opts$switched,
37
- _opts$stateSourceName = opts.stateSourceName,
38
- stateSourceName = _opts$stateSourceName === void 0 ? 'STATE' : _opts$stateSourceName;
39
-
40
- var nameType = _typeof(name$);
41
-
42
- if (!name$) throw new Error("Missing 'name$' parameter for switchable()");
43
-
44
- if (!(nameType === 'string' || nameType === 'function' || name$ instanceof Stream)) {
45
- throw new Error("Invalid 'name$' parameter for switchable(): expects Stream, String, or Function");
46
- }
47
-
48
- if (name$ instanceof Stream) {
49
- var withInitial$ = name$.compose(dropRepeats()).startWith(initial).remember();
50
- return function (sources) {
51
- return _switchable(factories, sources, withInitial$, switched);
52
- };
53
- } else {
54
- var mapFunction = nameType === 'function' && name$ || function (state) {
55
- return state[name$];
56
- };
57
-
58
- return function (sources) {
59
- var state$ = sources && (typeof stateSourceName === 'string' && sources[stateSourceName] || sources.STATE || sources.state).stream;
60
- if (!state$ instanceof Stream) throw new Error("Could not find the state source: ".concat(stateSourceName));
61
-
62
- var _name$ = state$.map(mapFunction).filter(function (name) {
63
- return typeof name === 'string';
64
- }).compose(dropRepeats()).startWith(initial).remember();
65
-
66
- return _switchable(factories, sources, _name$, switched, stateSourceName);
67
- };
68
- }
69
- }
70
- /**
71
- * create a group of components which can be switched between based on a stream of component names
72
- *
73
- * @param {Object} factories maps names to component creation functions
74
- * @param {Object} sources standard cycle sources object provided to each component
75
- * @param {Observable} name$ stream of names corresponding to the component names
76
- * @param {Array} switched which cycle sinks from the components should be `switched` when a new `name$` is emitted
77
- * @return {Object} cycle sinks object where the selected sinks are switched to the last component name emitted to `name$`
78
- *
79
- * any component sinks not dsignated in `switched` will be merged across all components
80
- */
81
-
82
- function _switchable(factories, sources, name$) {
83
- var switched = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['DOM'];
84
- var stateSourceName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'STATE';
85
- if (typeof switched === 'string') switched = [switched];
86
- var sinks = Object.entries(factories).map(function (_ref) {
87
- var _ref2 = _slicedToArray(_ref, 2),
88
- name = _ref2[0],
89
- factory = _ref2[1];
90
-
91
- if (sources[stateSourceName]) {
92
- var state$ = sources[stateSourceName].stream;
93
-
94
- var _switched = xs.combine(name$, state$).filter(function (_ref3) {
95
- var _ref4 = _slicedToArray(_ref3, 2),
96
- newComponentName = _ref4[0],
97
- _ = _ref4[1];
98
-
99
- return newComponentName == name;
100
- }).map(function (_ref5) {
101
- var _ref6 = _slicedToArray(_ref5, 2),
102
- _ = _ref6[0],
103
- state = _ref6[1];
104
-
105
- return state;
106
- }).remember();
107
-
108
- var state = new sources[stateSourceName].constructor(_switched, sources[stateSourceName]._name);
109
- return [name, factory(_objectSpread(_objectSpread({}, sources), {}, {
110
- state: state
111
- }))];
112
- }
113
-
114
- return [name, factory(sources)];
115
- });
116
- var switchedSinks = Object.keys(sources).reduce(function (obj, sinkName) {
117
- if (switched.includes(sinkName)) {
118
- obj[sinkName] = name$.map(function (newComponentName) {
119
- var sink = sinks.find(function (_ref7) {
120
- var _ref8 = _slicedToArray(_ref7, 2),
121
- componentName = _ref8[0],
122
- _ = _ref8[1];
123
-
124
- return componentName === newComponentName;
125
- });
126
- return sink && sink[1][sinkName] || xs.never();
127
- }).flatten().remember().startWith(undefined);
128
- } else {
129
- var definedSinks = sinks.filter(function (_ref9) {
130
- var _ref10 = _slicedToArray(_ref9, 2),
131
- _ = _ref10[0],
132
- sink = _ref10[1];
133
-
134
- return sink[sinkName] !== undefined;
135
- }).map(function (_ref11) {
136
- var _ref12 = _slicedToArray(_ref11, 2),
137
- _ = _ref12[0],
138
- sink = _ref12[1];
139
-
140
- return sink[sinkName];
141
- });
142
- obj[sinkName] = xs.merge.apply(xs, _toConsumableArray(definedSinks));
143
- }
144
-
145
- return obj;
146
- }, {});
147
- return switchedSinks;
148
- }