spyne 0.19.1 → 0.20.1
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/.eslintignore +2 -0
- package/.eslintrc.js +4 -3
- package/.travis.yml +24 -11
- package/karma.conf.js +77 -87
- package/lib/spyne.esm.js +15 -0
- package/lib/spyne.esm.js.map +1 -0
- package/lib/spyne.js +248 -248
- package/lib/spyne.umd.js +3 -0
- package/lib/spyne.umd.js.LICENSE.txt +16 -0
- package/package.json +48 -27
- package/rollup.config.js +26 -0
- package/src/spyne/channels/channel-fetch-class.js +39 -43
- package/src/spyne/channels/channel-payload-class.js +61 -74
- package/src/spyne/channels/channel-proxy.js +25 -26
- package/src/spyne/channels/channel.js +141 -149
- package/src/spyne/channels/channels-config.js +46 -47
- package/src/spyne/channels/channels-map.js +61 -65
- package/src/spyne/channels/spyne-channel-lifecycle.js +12 -12
- package/src/spyne/channels/spyne-channel-route.js +241 -250
- package/src/spyne/channels/spyne-channel-ui.js +213 -75
- package/src/spyne/channels/spyne-channel-window.js +157 -157
- package/src/spyne/spyne-app.js +32 -19
- package/src/spyne/spyne-plugins.js +55 -70
- package/src/spyne/spyne.js +23 -23
- package/src/spyne/utils/channel-config-validator.js +10 -10
- package/src/spyne/utils/channel-fetch-util.js +72 -55
- package/src/spyne/utils/channel-payload-filter.js +89 -100
- package/src/spyne/utils/deep-merge.js +31 -29
- package/src/spyne/utils/frp-tools.js +108 -92
- package/src/spyne/utils/gc.js +6 -6
- package/src/spyne/utils/mixins/base-core-mixins.js +17 -15
- package/src/spyne/utils/mixins/base-streams-mixins.js +9 -9
- package/src/spyne/utils/route-channel-updater.js +23 -29
- package/src/spyne/utils/safe-clone.js +40 -58
- package/src/spyne/utils/sanitize-html.js +35 -0
- package/src/spyne/utils/security-policy.js +11 -0
- package/src/spyne/utils/spyne-app-properties.js +110 -114
- package/src/spyne/utils/spyne-logger.js +4 -11
- package/src/spyne/utils/spyne-plugins-methods.js +38 -63
- package/src/spyne/utils/spyne-trait.js +33 -33
- package/src/spyne/utils/spyne-utils-channel-route-url.js +229 -153
- package/src/spyne/utils/spyne-utils-channel-route.js +128 -138
- package/src/spyne/utils/spyne-utils-channel-window.js +39 -39
- package/src/spyne/utils/viewstream-animations.js +12 -12
- package/src/spyne/utils/viewstream-observables.js +45 -45
- package/src/spyne/views/dom-element-template.js +111 -114
- package/src/spyne/views/dom-element.js +82 -84
- package/src/spyne/views/view-stream-broadcaster.js +66 -62
- package/src/spyne/views/view-stream-element.js +105 -106
- package/src/spyne/views/view-stream-payload.js +25 -27
- package/src/spyne/views/view-stream-selector.js +157 -163
- package/src/spyne/views/view-stream.js +416 -640
- package/src/tests/channels/channel-dom.test.js +15 -15
- package/src/tests/channels/channel-fetch.test.js +51 -62
- package/src/tests/channels/channel-payload-class.test.js +50 -63
- package/src/tests/channels/channel-payload-filter.test.js +133 -193
- package/src/tests/channels/channel-route.test.js +102 -112
- package/src/tests/channels/channel-stream-item.test.js +19 -19
- package/src/tests/channels/channel-ui.test.js +15 -27
- package/src/tests/channels/channel-util-dom.test.js +31 -31
- package/src/tests/channels/channel.test.js +20 -25
- package/src/tests/channels/route-utils.test.js +61 -66
- package/src/tests/channels/url-utils.test.js +151 -151
- package/src/tests/channels/view-stream-broadcaster.test.js +7 -7
- package/src/tests/import.test.js +5 -5
- package/src/tests/index.js +6 -7
- package/src/tests/index.test.js +6 -8
- package/src/tests/mocks/channel-payload-data.js +218 -220
- package/src/tests/mocks/enhancer.test.js +5 -5
- package/src/tests/mocks/payload-ui.js +87 -90
- package/src/tests/mocks/routes-data.js +264 -266
- package/src/tests/mocks/spyne-docs.mocks.js +3 -3
- package/src/tests/mocks/template-renderer.mocks.js +47 -47
- package/src/tests/mocks/utils-data.js +78 -79
- package/src/tests/mocks/viewstream-internal-payload.mocks.js +50 -50
- package/src/tests/mocks/window-events-arr.js +1 -1
- package/src/tests/package-json.spec.test.js +9 -0
- package/src/tests/spyne-app.test.js +15 -18
- package/src/tests/spyne-plugin.test.js +16 -20
- package/src/tests/utils/channel-action-filter.test.js +84 -86
- package/src/tests/utils/channel-data-packet-generator.unused.js +62 -86
- package/src/tests/utils/channel-fetch-util.test.js +64 -66
- package/src/tests/utils/frp-tools.test.js +19 -19
- package/src/tests/utils/plugins-methods.test.js +31 -55
- package/src/tests/utils/security.test.js +10 -0
- package/src/tests/utils/spyne-app-properties.test.js +4 -8
- package/src/tests/views/dom-el-selectors.test.js +112 -119
- package/src/tests/views/dom-el-template-proxy.test.js +7 -0
- package/src/tests/views/dom-el-template.test.js +186 -156
- package/src/tests/views/dom-el.test.js +58 -56
- package/src/tests/views/view-stream-enhancer-loader.test.js +2 -2
- package/src/tests/views/view-stream-enhancer.test.js +11 -11
- package/src/tests/views/view-stream.test.js +22 -33
- package/webpack.config.js +76 -67
- package/docs/-_%20Solves%20equations%20of%20the%20form%20a%20_%20x%20=%20b.html +0 -487
- package/docs/DomItem.html +0 -298
- package/docs/DomItem_DomItem.html +0 -314
- package/docs/ViewStream.html +0 -2249
- package/docs/ViewStream_ViewStream.html +0 -503
- package/docs/custom/css/jsdoc-viewstream.css +0 -377
- package/docs/custom/layout.tmpl +0 -47
- package/docs/dom-item.js.html +0 -213
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/global.html +0 -548
- package/docs/index-custom.html +0 -79
- package/docs/index.html +0 -82
- package/docs/jsdoc.config.json +0 -22
- package/docs/scripts/linenumber.js +0 -25
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/scripts/prettify/lang-css.js +0 -2
- package/docs/scripts/prettify/prettify.js +0 -28
- package/docs/styles/jsdoc-default.css +0 -358
- package/docs/styles/prettify-jsdoc.css +0 -111
- package/docs/styles/prettify-tomorrow.css +0 -132
- package/docs/view-stream.js.html +0 -767
|
@@ -19,16 +19,15 @@ import {
|
|
|
19
19
|
any,
|
|
20
20
|
curry,
|
|
21
21
|
lte
|
|
22
|
-
|
|
22
|
+
, map as rMap
|
|
23
|
+
} from 'ramda'
|
|
23
24
|
|
|
24
|
-
import {SpyneAppProperties} from './spyne-app-properties'
|
|
25
|
+
import { SpyneAppProperties } from './spyne-app-properties'
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const isNonEmptyStr = allPass([is(String), isNotEmpty]);
|
|
31
|
-
const isNonEmptyArr = allPass([is(Array), isNotEmpty]);
|
|
27
|
+
const isNotArr = compose(not, is(Array))
|
|
28
|
+
const isNotEmpty = compose(not, isEmpty)
|
|
29
|
+
const isNonEmptyStr = allPass([is(String), isNotEmpty])
|
|
30
|
+
const isNonEmptyArr = allPass([is(Array), isNotEmpty])
|
|
32
31
|
const isObjectFn = compose(allPass([isNotArr, is(Object)]))
|
|
33
32
|
const isNonEmptyObjectFn = compose(allPass([isNotEmpty, isNotArr, is(Object)]))
|
|
34
33
|
|
|
@@ -99,170 +98,160 @@ export class ChannelPayloadFilter {
|
|
|
99
98
|
* .subscribe(myChannelMethod);
|
|
100
99
|
*
|
|
101
100
|
*/
|
|
102
|
-
constructor(selector, filters={}, debugLabel, testMode) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const selectorIsObj = isObjectFn(selector);
|
|
107
|
-
|
|
108
|
-
if(selectorIsObj){
|
|
109
|
-
filters = selector;
|
|
110
|
-
selector = prop('selector', filters);
|
|
111
|
-
testMode = testMode || prop("testMode", filters);
|
|
101
|
+
constructor(selector, filters = {}, debugLabel, testMode) {
|
|
102
|
+
const selectorIsObj = isObjectFn(selector)
|
|
112
103
|
|
|
104
|
+
if (selectorIsObj) {
|
|
105
|
+
filters = selector
|
|
106
|
+
selector = prop('selector', filters)
|
|
107
|
+
testMode = testMode || prop('testMode', filters)
|
|
113
108
|
}
|
|
114
109
|
|
|
110
|
+
const debugLabelArr = [debugLabel, prop('debugLabel', filters)]
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
debugLabel = compose(find(is(String)))(debugLabelArr);
|
|
112
|
+
debugLabel = compose(find(is(String)))(debugLabelArr)
|
|
119
113
|
|
|
120
114
|
let props = omit(['debugLabel', 'label', 'selector', 'props', 'testMode', 'propFilters'], filters)
|
|
121
|
-
if (filters.props!==undefined) {
|
|
115
|
+
if (filters.props !== undefined) {
|
|
122
116
|
props = mergeAll([filters.props, props])
|
|
123
|
-
|
|
124
|
-
} else if (filters.propFilters!==undefined) {
|
|
117
|
+
} else if (filters.propFilters !== undefined) {
|
|
125
118
|
props = mergeAll([filters.propFilters, props])
|
|
126
119
|
}
|
|
127
120
|
|
|
128
|
-
filters
|
|
121
|
+
filters.propFilters = props
|
|
129
122
|
|
|
130
|
-
|
|
123
|
+
const { propFilters } = filters
|
|
131
124
|
|
|
125
|
+
const addStringSelectorFilter = isNonEmptyStr(selector) ? ChannelPayloadFilter.filterSelector([selector], debugLabel) : undefined
|
|
126
|
+
const addArraySelectorFilter = isNonEmptyArr(selector) ? ChannelPayloadFilter.filterSelector(selector, debugLabel) : undefined
|
|
127
|
+
const addDataFilter = isNonEmptyObjectFn(propFilters) ? ChannelPayloadFilter.filterData(propFilters, debugLabel) : undefined
|
|
132
128
|
|
|
133
|
-
|
|
134
|
-
const addArraySelectorFilter = isNonEmptyArr(selector) ? ChannelPayloadFilter.filterSelector(selector, debugLabel) : undefined;
|
|
135
|
-
const addDataFilter = isNonEmptyObjectFn(propFilters) ? ChannelPayloadFilter.filterData(propFilters, debugLabel) : undefined;
|
|
129
|
+
let filtersArr = reject(isNil, [addStringSelectorFilter, addArraySelectorFilter, addDataFilter])
|
|
136
130
|
|
|
137
|
-
|
|
131
|
+
// IF ARRAY IS EMPTY ALWAYS RETURN FALSE;
|
|
138
132
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const filtersAreEmpty = isEmpty(filtersArr);
|
|
142
|
-
|
|
143
|
-
if (filtersAreEmpty){
|
|
144
|
-
filtersArr = [always(false)];
|
|
145
|
-
if (SpyneAppProperties.debug === true && testMode!==true){
|
|
146
|
-
console.warn(`Spyne Warning: The Channel Filter, with selector: ${selector}, and propFilters:${propFilters} appears to be empty!`);
|
|
147
|
-
}
|
|
133
|
+
const filtersAreEmpty = isEmpty(filtersArr)
|
|
148
134
|
|
|
135
|
+
if (filtersAreEmpty) {
|
|
136
|
+
filtersArr = [always(false)]
|
|
137
|
+
if (SpyneAppProperties.debug === true && testMode !== true) {
|
|
138
|
+
console.warn(`Spyne Warning: The Channel Filter, with selector: ${selector}, and propFilters:${propFilters} appears to be empty!`)
|
|
149
139
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
140
|
+
}
|
|
141
|
+
if (testMode === true) {
|
|
142
|
+
return { selector, propFilters, debugLabel, filters, testMode, filtersAreEmpty }
|
|
143
|
+
}
|
|
153
144
|
|
|
154
|
-
return allPass(filtersArr)
|
|
145
|
+
return allPass(filtersArr)
|
|
155
146
|
}
|
|
156
147
|
|
|
157
148
|
static filterData(filterJson, filterdebugLabel) {
|
|
158
|
-
const debugLabel = filterdebugLabel
|
|
149
|
+
const debugLabel = filterdebugLabel
|
|
159
150
|
|
|
160
|
-
|
|
151
|
+
const compareData = () => {
|
|
161
152
|
// DO NOT ALLOW AN EMPTY OBJECT TO RETURN TRUEs
|
|
162
153
|
if (isEmpty(filterJson)) {
|
|
163
|
-
return always(false)
|
|
154
|
+
return always(false)
|
|
164
155
|
}
|
|
165
156
|
|
|
166
157
|
// CHECKS ALL VALUES IN JSON TO DETERMINE IF THERE ARE FILTERING METHODS
|
|
167
158
|
|
|
168
|
-
const createCurryComparator = compareStr => (str)=>{
|
|
169
|
-
return str===compareStr
|
|
170
|
-
}
|
|
171
|
-
const checkToConvertToFn = (val, key, obj)=>
|
|
172
|
-
|
|
159
|
+
const createCurryComparator = compareStr => (str) => {
|
|
160
|
+
return str === compareStr
|
|
161
|
+
}
|
|
162
|
+
const checkToConvertToFn = (val, key, obj) => {
|
|
163
|
+
const fnVal = is(String, val) === true ? createCurryComparator(val) : val
|
|
164
|
+
return fnVal
|
|
165
|
+
}
|
|
166
|
+
filterJson = rMap(checkToConvertToFn, filterJson)
|
|
173
167
|
|
|
174
168
|
// TAP LOGGER
|
|
175
|
-
const tapLogger = (comparedObj)=>{
|
|
176
|
-
if (debugLabel===undefined){
|
|
177
|
-
return comparedObj
|
|
169
|
+
const tapLogger = (comparedObj) => {
|
|
170
|
+
if (debugLabel === undefined) {
|
|
171
|
+
return comparedObj
|
|
178
172
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
const propsBooleans = {}
|
|
174
|
+
const mapBools = (value, key) => {
|
|
175
|
+
propsBooleans[key] = value(prop(key, comparedObj))
|
|
176
|
+
}
|
|
177
|
+
forEachObjIndexed(mapBools, filterJson)
|
|
178
|
+
console.log(`%c CHANNEL PAYLOAD FILTER DEBUGGER ["${debugLabel}"] - values: `, 'color:orange;', { propsBooleans, comparedObj })
|
|
183
179
|
|
|
184
|
-
return comparedObj
|
|
185
|
-
}
|
|
180
|
+
return comparedObj
|
|
181
|
+
}
|
|
186
182
|
|
|
187
183
|
// END TAP LOGGER
|
|
188
|
-
|
|
184
|
+
const fMethod = where(filterJson)
|
|
189
185
|
|
|
190
|
-
|
|
191
|
-
const {payload, srcElement, event} = v || {}
|
|
192
|
-
const o = Object.assign({}, v, event, payload)
|
|
193
|
-
//console.log('o is ',o);
|
|
194
|
-
return o
|
|
186
|
+
const getFilteringObj = (v) => {
|
|
187
|
+
const { payload, srcElement, event } = v || {}
|
|
188
|
+
const o = Object.assign({}, v, srcElement, event, payload)
|
|
189
|
+
// console.log('o is ',o);
|
|
190
|
+
return o
|
|
195
191
|
}
|
|
196
192
|
|
|
193
|
+
return compose(fMethod, tapLogger, defaultTo({}), getFilteringObj)
|
|
194
|
+
}
|
|
197
195
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
return compareData();
|
|
196
|
+
return compareData()
|
|
203
197
|
}
|
|
204
198
|
|
|
205
|
-
|
|
206
199
|
static checkPayloadSelector(arr, debugLabel, srcPayload) {
|
|
207
|
-
|
|
208
200
|
// ELEMENT FROM PAYLOADs
|
|
209
|
-
const {payload, srcElement, event} = srcPayload || {}
|
|
201
|
+
const { payload, srcElement, event } = srcPayload || {}
|
|
210
202
|
|
|
211
203
|
const reduceFindEl = (acc, src) => {
|
|
212
|
-
const el = prop('el', src)
|
|
213
|
-
if (ChannelPayloadFilter.elIsDomElement(el) && acc===undefined){
|
|
214
|
-
acc = el
|
|
204
|
+
const el = prop('el', src)
|
|
205
|
+
if (ChannelPayloadFilter.elIsDomElement(el) && acc === undefined) {
|
|
206
|
+
acc = el
|
|
215
207
|
}
|
|
216
|
-
return acc
|
|
208
|
+
return acc
|
|
217
209
|
}
|
|
218
210
|
|
|
219
|
-
const el = [srcElement, payload, prop('srcElement', event), srcPayload].reduce(reduceFindEl, undefined)
|
|
220
|
-
|
|
211
|
+
const el = [srcElement, payload, prop('srcElement', event), srcPayload].reduce(reduceFindEl, undefined)
|
|
221
212
|
|
|
222
213
|
// RETURN BOOLEAN MATCH WITH PAYLOAD EL
|
|
223
|
-
const compareEls = (elCompare) => elCompare.isEqualNode((el))
|
|
214
|
+
const compareEls = (elCompare) => elCompare.isEqualNode((el))
|
|
224
215
|
|
|
225
216
|
// LOOP THROUGH NODES IN querySelectorAll()
|
|
226
217
|
const mapNodeArrWithEl = (sel) => {
|
|
227
218
|
// convert nodelist to array of els
|
|
228
|
-
|
|
219
|
+
const nodeArr = flatten(document.querySelectorAll(sel))
|
|
229
220
|
// els array to boolean array
|
|
230
|
-
return rMap(compareEls, nodeArr)
|
|
231
|
-
}
|
|
221
|
+
return rMap(compareEls, nodeArr)
|
|
222
|
+
}
|
|
232
223
|
|
|
233
|
-
if (debugLabel!==undefined){
|
|
234
|
-
|
|
235
|
-
const selectorsArr = arr
|
|
236
|
-
console.log(`%c CHANNEL PAYLOAD FILTER DEBUGGER ["${debugLabel}"] - selectors: `,
|
|
224
|
+
if (debugLabel !== undefined) {
|
|
225
|
+
const nodeArrResultsDebugger = compose(flatten, rMap(mapNodeArrWithEl))(arr)
|
|
226
|
+
const selectorsArr = arr
|
|
227
|
+
console.log(`%c CHANNEL PAYLOAD FILTER DEBUGGER ["${debugLabel}"] - selectors: `, 'color:orange;', { el, selectorsArr, nodeArrResultsDebugger })
|
|
237
228
|
}
|
|
238
229
|
|
|
239
230
|
// CHECK IF PAYLOAD EL EXISTS
|
|
240
231
|
if (typeof (el) !== 'object') {
|
|
241
|
-
return false
|
|
232
|
+
return false
|
|
242
233
|
}
|
|
243
234
|
|
|
244
235
|
// LOOP THROUGH ALL SELECTORS IN MAIN ARRAY
|
|
245
|
-
|
|
236
|
+
const nodeArrResult = compose(flatten, rMap(mapNodeArrWithEl))(arr)
|
|
246
237
|
if (isEmpty(nodeArrResult) === true) {
|
|
247
|
-
return false
|
|
238
|
+
return false
|
|
248
239
|
}
|
|
249
240
|
|
|
250
|
-
return any(equals(true), nodeArrResult)
|
|
241
|
+
return any(equals(true), nodeArrResult)
|
|
251
242
|
}
|
|
252
243
|
|
|
253
244
|
static elIsDomElement(o) {
|
|
254
|
-
if (is(String,o)){
|
|
255
|
-
o = document.querySelector(o)
|
|
245
|
+
if (is(String, o)) {
|
|
246
|
+
o = document.querySelector(o)
|
|
256
247
|
}
|
|
257
248
|
|
|
258
|
-
|
|
259
|
-
return compose(lte(0), defaultTo(-1), prop('nodeType'))(o);
|
|
249
|
+
return compose(lte(0), defaultTo(-1), prop('nodeType'))(o)
|
|
260
250
|
}
|
|
261
251
|
|
|
262
|
-
|
|
263
252
|
static filterSelector(selectorArr, debugLabel) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return payloadCheck(arr, debugLabel)
|
|
253
|
+
const arr = reject(isEmpty, selectorArr)
|
|
254
|
+
const payloadCheck = curry(ChannelPayloadFilter.checkPayloadSelector)
|
|
255
|
+
return payloadCheck(arr, debugLabel)
|
|
267
256
|
}
|
|
268
257
|
}
|
|
@@ -1,73 +1,75 @@
|
|
|
1
1
|
function isMergeableObject(val) {
|
|
2
|
-
|
|
3
|
-
return nonNullObject && Object.prototype.toString.call(val) !== '[object RegExp]' && Object.prototype.toString.call(val) !== '[object Date]'
|
|
2
|
+
const nonNullObject = val && typeof val === 'object'
|
|
3
|
+
return nonNullObject && Object.prototype.toString.call(val) !== '[object RegExp]' && Object.prototype.toString.call(val) !== '[object Date]'
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
function emptyTarget(val) {
|
|
7
|
-
return Array.isArray(val) ? [] : {}
|
|
7
|
+
return Array.isArray(val) ? [] : {}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
function cloneIfNecessary(value, optionsArgument) {
|
|
11
|
-
|
|
12
|
-
return (clone && isMergeableObject(value))
|
|
13
|
-
value,
|
|
11
|
+
const clone = optionsArgument && optionsArgument.clone === true
|
|
12
|
+
return (clone && isMergeableObject(value))
|
|
13
|
+
? deepMerge(emptyTarget(value),
|
|
14
|
+
value, optionsArgument)
|
|
15
|
+
: value
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
function defaultArrayMerge(target, source, optionsArgument) {
|
|
17
|
-
|
|
19
|
+
const destination = target.slice()
|
|
18
20
|
source.forEach(function(e, i) {
|
|
19
21
|
if (typeof destination[i] === 'undefined') {
|
|
20
|
-
destination[i] = cloneIfNecessary(e, optionsArgument)
|
|
22
|
+
destination[i] = cloneIfNecessary(e, optionsArgument)
|
|
21
23
|
} else if (isMergeableObject(e)) {
|
|
22
|
-
destination[i] = deepMerge(target[i], e, optionsArgument)
|
|
24
|
+
destination[i] = deepMerge(target[i], e, optionsArgument)
|
|
23
25
|
} else if (target.indexOf(e) === -1) {
|
|
24
|
-
destination.push(cloneIfNecessary(e, optionsArgument))
|
|
26
|
+
destination.push(cloneIfNecessary(e, optionsArgument))
|
|
25
27
|
}
|
|
26
|
-
})
|
|
27
|
-
return destination
|
|
28
|
+
})
|
|
29
|
+
return destination
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
function mergeObject(target, source, optionsArgument) {
|
|
31
|
-
|
|
33
|
+
const destination = {}
|
|
32
34
|
if (isMergeableObject(target)) {
|
|
33
35
|
Object.keys(target).forEach(function(key) {
|
|
34
|
-
destination[key] = cloneIfNecessary(target[key], optionsArgument)
|
|
35
|
-
})
|
|
36
|
+
destination[key] = cloneIfNecessary(target[key], optionsArgument)
|
|
37
|
+
})
|
|
36
38
|
}
|
|
37
39
|
Object.keys(source).forEach(function(key) {
|
|
38
40
|
if (!isMergeableObject(source[key]) || !target[key]) {
|
|
39
|
-
destination[key] = cloneIfNecessary(source[key], optionsArgument)
|
|
41
|
+
destination[key] = cloneIfNecessary(source[key], optionsArgument)
|
|
40
42
|
} else {
|
|
41
|
-
destination[key] = deepMerge(target[key], source[key], optionsArgument)
|
|
43
|
+
destination[key] = deepMerge(target[key], source[key], optionsArgument)
|
|
42
44
|
}
|
|
43
|
-
})
|
|
44
|
-
return destination
|
|
45
|
+
})
|
|
46
|
+
return destination
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
function deepMerge(target, source, optionsArgument) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const array = Array.isArray(source)
|
|
51
|
+
const options = optionsArgument || { arrayMerge: defaultArrayMerge }
|
|
52
|
+
const arrayMerge = options.arrayMerge || defaultArrayMerge
|
|
51
53
|
|
|
52
54
|
if (array) {
|
|
53
55
|
return Array.isArray(target)
|
|
54
56
|
? arrayMerge(target, source, optionsArgument)
|
|
55
|
-
: cloneIfNecessary(source, optionsArgument)
|
|
57
|
+
: cloneIfNecessary(source, optionsArgument)
|
|
56
58
|
} else {
|
|
57
|
-
return mergeObject(target, source, optionsArgument)
|
|
59
|
+
return mergeObject(target, source, optionsArgument)
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
deepMerge.all = function deepmergeAll(array, optionsArgument) {
|
|
62
64
|
if (!Array.isArray(array) || array.length < 2) {
|
|
63
65
|
throw new Error(
|
|
64
|
-
'first argument should be an array with at least two elements')
|
|
66
|
+
'first argument should be an array with at least two elements')
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
// we are sure there are at least 2 values, so it is safe to have no initial value
|
|
68
70
|
return array.reduce(function(prev, next) {
|
|
69
|
-
return deepMerge(prev, next, optionsArgument)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
71
|
+
return deepMerge(prev, next, optionsArgument)
|
|
72
|
+
})
|
|
73
|
+
}
|
|
72
74
|
|
|
73
|
-
export { deepMerge }
|
|
75
|
+
export { deepMerge }
|
|
@@ -1,92 +1,85 @@
|
|
|
1
|
-
import{defaultTo, match, forEach, test, includes, without,complement, isEmpty, values, isNil, filter, __, keys, compose, head, map, cond, T, allPass, concat, uniq} from 'ramda'
|
|
1
|
+
import { defaultTo, match, forEach, test, includes, without, complement, isEmpty, values, isNil, filter, __, keys, compose, head, map, cond, T, allPass, concat, uniq } from 'ramda'
|
|
2
2
|
const isIOS = () => {
|
|
3
|
-
|
|
3
|
+
const userAgent = window.navigator.userAgent.toLowerCase()
|
|
4
4
|
// let safari = /safari/.test(userAgent);
|
|
5
|
-
|
|
6
|
-
return ios === true
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const delayCall = async(fn, time)=>{
|
|
5
|
+
const ios = /iphone|ipod|ipad/.test(userAgent)
|
|
6
|
+
return ios === true
|
|
7
|
+
}
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
const delayCall = async(fn, time) => {
|
|
10
|
+
function sleep(ms) {
|
|
13
11
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
const timeoutHandler = async() => {
|
|
17
|
-
await sleep(1)
|
|
18
|
-
window.requestAnimationFrame(fn)
|
|
15
|
+
await sleep(1)
|
|
16
|
+
window.requestAnimationFrame(fn)
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
window.setTimeout(timeoutHandler, time)
|
|
22
|
-
|
|
23
|
-
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
22
|
const getConstructorName = (obj) => {
|
|
30
23
|
if (obj.constructor.name !== undefined) {
|
|
31
|
-
return obj.constructor.name
|
|
24
|
+
return obj.constructor.name
|
|
32
25
|
}
|
|
33
|
-
const re = /^(function\s)(\w+)(\(.*)
|
|
34
|
-
|
|
35
|
-
return defaultTo(String(str).substr(0, 12), match(re, str)[2])
|
|
36
|
-
}
|
|
26
|
+
const re = /^(function\s)(\w+)(\(.*)$/
|
|
27
|
+
const str = obj.toString()
|
|
28
|
+
return defaultTo(String(str).substr(0, 12), match(re, str)[2])
|
|
29
|
+
}
|
|
37
30
|
|
|
38
31
|
const arrFromMapKeys = (map) => {
|
|
39
|
-
|
|
40
|
-
const addKeysToArr = (v, k, i) => arr.push(k)
|
|
41
|
-
forEach(addKeysToArr, map)
|
|
42
|
-
return arr
|
|
43
|
-
}
|
|
32
|
+
const arr = []
|
|
33
|
+
const addKeysToArr = (v, k, i) => arr.push(k)
|
|
34
|
+
forEach(addKeysToArr, map)
|
|
35
|
+
return arr
|
|
36
|
+
}
|
|
44
37
|
|
|
45
38
|
const findStrFromRegexArr = (obj, str) => {
|
|
46
39
|
if (obj[str] !== undefined) {
|
|
47
|
-
return str
|
|
40
|
+
return str
|
|
48
41
|
}
|
|
49
|
-
const checkIfMatch = s => test(new RegExp(s), str)
|
|
50
|
-
const checkStrMatch = includes(str)
|
|
51
|
-
const checkIfRegExMatch = compose(includes(true), map(checkIfMatch))
|
|
42
|
+
const checkIfMatch = s => test(new RegExp(s), str)
|
|
43
|
+
const checkStrMatch = includes(str)
|
|
44
|
+
const checkIfRegExMatch = compose(includes(true), map(checkIfMatch))
|
|
52
45
|
const runMatchChecks = cond([
|
|
53
46
|
[checkStrMatch, () => str],
|
|
54
47
|
[checkIfRegExMatch, () => str],
|
|
55
48
|
[T, () => undefined]
|
|
56
|
-
])
|
|
57
|
-
return runMatchChecks(obj)
|
|
58
|
-
}
|
|
49
|
+
])
|
|
50
|
+
return runMatchChecks(obj)
|
|
51
|
+
}
|
|
59
52
|
|
|
60
53
|
const findStrOrRegexMatchStr = (obj, str) => {
|
|
61
54
|
if (obj[str] !== undefined) {
|
|
62
|
-
return str
|
|
55
|
+
return str
|
|
63
56
|
}
|
|
64
|
-
const createRe = s => new RegExp(s)
|
|
65
|
-
|
|
66
|
-
return checkerIfRegexMatchExists(keys(obj))
|
|
67
|
-
}
|
|
57
|
+
const createRe = s => new RegExp(s)
|
|
58
|
+
const checkerIfRegexMatchExists = compose(head, filter(compose(test(__, str), createRe)))
|
|
59
|
+
return checkerIfRegexMatchExists(keys(obj))
|
|
60
|
+
}
|
|
68
61
|
|
|
69
62
|
const closest = (array, num) => {
|
|
70
|
-
let i = 0
|
|
71
|
-
let minDiff = 1000
|
|
72
|
-
let ans
|
|
63
|
+
let i = 0
|
|
64
|
+
let minDiff = 1000
|
|
65
|
+
let ans
|
|
73
66
|
for (i in array) {
|
|
74
|
-
|
|
67
|
+
const m = Math.abs(num - array[i])
|
|
75
68
|
if (m < minDiff) {
|
|
76
|
-
minDiff = m
|
|
77
|
-
ans = array[i]
|
|
69
|
+
minDiff = m
|
|
70
|
+
ans = array[i]
|
|
78
71
|
}
|
|
79
72
|
}
|
|
80
|
-
return ans
|
|
81
|
-
}
|
|
73
|
+
return ans
|
|
74
|
+
}
|
|
82
75
|
|
|
83
76
|
const convertDomStringMapToObj = (domMap) => {
|
|
84
|
-
|
|
85
|
-
for (
|
|
86
|
-
obj[d] = domMap[d]
|
|
77
|
+
const obj = {}
|
|
78
|
+
for (const d in domMap) {
|
|
79
|
+
obj[d] = domMap[d]
|
|
87
80
|
}
|
|
88
|
-
return obj
|
|
89
|
-
}
|
|
81
|
+
return obj
|
|
82
|
+
}
|
|
90
83
|
|
|
91
84
|
// const passPageData = pick(['params', 'routeId', 'data'], __);
|
|
92
85
|
|
|
@@ -94,72 +87,95 @@ const subscribeFn = {
|
|
|
94
87
|
next: x => console.log(`next ${x}`),
|
|
95
88
|
error: x => console.log(`error ${x}`),
|
|
96
89
|
complete: x => console.log(`complete ${x}`)
|
|
97
|
-
}
|
|
90
|
+
}
|
|
98
91
|
|
|
99
92
|
const right = x => ({
|
|
100
93
|
map: f => right(f(x)),
|
|
101
94
|
fold: (f, g) => g(x),
|
|
102
95
|
inspect: () => `right(${x})`
|
|
103
96
|
|
|
104
|
-
})
|
|
97
|
+
})
|
|
105
98
|
|
|
106
99
|
const ifNilThenUpdate = (val, newVal) => {
|
|
107
|
-
|
|
108
|
-
return isNilBool ? newVal : val
|
|
109
|
-
}
|
|
100
|
+
const isNilBool = isNil(val)
|
|
101
|
+
return isNilBool ? newVal : val
|
|
102
|
+
}
|
|
110
103
|
|
|
111
104
|
const left = x => ({
|
|
112
105
|
map: f => left(x),
|
|
113
106
|
fold: (f, g) => f(x),
|
|
114
107
|
inspect: () => `left(${x})`
|
|
115
|
-
})
|
|
108
|
+
})
|
|
116
109
|
|
|
117
110
|
const checkIfObjIsNotEmptyOrNil = (obj) => {
|
|
118
|
-
const isNotEmpty = compose(complement(isEmpty), head, values)
|
|
119
|
-
const isNotNil = compose(complement(isNil), head, values)
|
|
120
|
-
const isNotNilAndIsNotEmpty = allPass([isNotEmpty, isNotNil])
|
|
121
|
-
return isNotNilAndIsNotEmpty(obj)
|
|
122
|
-
}
|
|
111
|
+
const isNotEmpty = compose(complement(isEmpty), head, values)
|
|
112
|
+
const isNotNil = compose(complement(isNil), head, values)
|
|
113
|
+
const isNotNilAndIsNotEmpty = allPass([isNotEmpty, isNotNil])
|
|
114
|
+
return isNotNilAndIsNotEmpty(obj)
|
|
115
|
+
}
|
|
123
116
|
|
|
124
|
-
const fromNullable = x => x !== null ? right(x) : left(null)
|
|
117
|
+
const fromNullable = x => x !== null ? right(x) : left(null)
|
|
125
118
|
|
|
126
119
|
const findInObj = (obj, val, error = null) => {
|
|
127
|
-
const found = obj[val]
|
|
128
|
-
return found ? right(found) : left(error)
|
|
129
|
-
}
|
|
120
|
+
const found = obj[val]
|
|
121
|
+
return found ? right(found) : left(error)
|
|
122
|
+
}
|
|
130
123
|
const pullRouteInfo = () => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return { routeId, params }
|
|
135
|
-
}
|
|
124
|
+
const str = pullHashAndSlashFromPath(window.location.hash)
|
|
125
|
+
const routeId = pullMainRoute(str)
|
|
126
|
+
const params = pullParams(str)
|
|
127
|
+
return { routeId, params }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getAllMethodNames(instance, omittedMethods = []) {
|
|
131
|
+
// Optionally rename `instance` to something more descriptive:
|
|
132
|
+
const baseClassMethodsArr = ['length', 'name', 'prototype', 'constructor']
|
|
133
|
+
const combinedOmittedMethods = concat(baseClassMethodsArr, omittedMethods)
|
|
134
|
+
|
|
135
|
+
// Filter out omitted
|
|
136
|
+
const omitPropsFromArr = compose(without(combinedOmittedMethods), uniq)
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
// Pull out instance methods
|
|
139
|
+
const methods = omitPropsFromArr(
|
|
140
|
+
Object.getOwnPropertyNames(instance.constructor.prototype)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
// Pull out static methods
|
|
144
|
+
const staticMethods = omitPropsFromArr(
|
|
145
|
+
Object.getOwnPropertyNames(instance.constructor)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
const allMethods = concat(methods, staticMethods)
|
|
149
|
+
|
|
150
|
+
return { methods, staticMethods, allMethods }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* const getAllMethodNames3 = (_this = this, omittedMethods = []) => {
|
|
138
154
|
const getPropNamesArr = (obj = this, omittedMethods = []) => {
|
|
139
|
-
return Object.getOwnPropertyNames(obj)
|
|
140
|
-
}
|
|
155
|
+
return Object.getOwnPropertyNames(obj)
|
|
156
|
+
}
|
|
141
157
|
// Filter Methods
|
|
142
|
-
|
|
143
|
-
omittedMethods = concat(baseClassMethodsArr, omittedMethods)
|
|
144
|
-
|
|
158
|
+
const baseClassMethodsArr = ['length', 'name', 'prototype', 'constructor']
|
|
159
|
+
omittedMethods = concat(baseClassMethodsArr, omittedMethods)
|
|
160
|
+
const omitPropsFromArr = compose(without(omittedMethods), uniq)
|
|
145
161
|
|
|
146
162
|
// PULL OUT METHOD NAMES
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
163
|
+
const methods = omitPropsFromArr(Object.getOwnPropertyNames(_this.constructor.prototype))
|
|
164
|
+
const staticMethods = omitPropsFromArr(getPropNamesArr(_this.constructor))
|
|
165
|
+
const allMethods = concat(methods, staticMethods)
|
|
150
166
|
|
|
151
|
-
return { methods, staticMethods, allMethods }
|
|
167
|
+
return { methods, staticMethods, allMethods }
|
|
152
168
|
// return 'fn';
|
|
153
|
-
}
|
|
169
|
+
} */
|
|
154
170
|
|
|
155
171
|
// ROUTE REGEX EXPRESSIONS
|
|
156
|
-
const removeSlashes = str => str.replace(/^(\/)(.*)/g, '$2')
|
|
157
|
-
const routeRE = /^(\/?)(\w*)(\/?)(.*)/g
|
|
158
|
-
const pullHashAndSlashFromPath = (str) => str.replace(/^(#\/?)(.*)/, '$2')
|
|
159
|
-
const pullSlashFromPath = (str) => str.replace(/^(\/?)(.*)/, '$2')
|
|
160
|
-
const pullMainRoute = (str) => str.replace(routeRE, '$2')
|
|
161
|
-
const pullParams = (str) => str.replace(routeRE, '$4')
|
|
162
|
-
const pullTranslateX = str => str.replace(/^(matrix)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*)(,.*)/, '$6')
|
|
163
|
-
const pullTranslateY = str => str.replace(/^(matrix)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d)(.*)/, '$7')
|
|
164
|
-
const pullTranslateYFromHeader = str => str.replace(/^(transform: matrix)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*)(\).*;)/, '$6')
|
|
165
|
-
export { getConstructorName, arrFromMapKeys, getAllMethodNames, findStrOrRegexMatchStr, findStrFromRegexArr, checkIfObjIsNotEmptyOrNil, isIOS, pullRouteInfo, pullTranslateYFromHeader, pullSlashFromPath, pullHashAndSlashFromPath, closest, pullTranslateY, pullTranslateX, pullMainRoute, pullParams, right, left, fromNullable, findInObj, ifNilThenUpdate, removeSlashes, subscribeFn, convertDomStringMapToObj, delayCall }
|
|
172
|
+
const removeSlashes = str => str.replace(/^(\/)(.*)/g, '$2')
|
|
173
|
+
const routeRE = /^(\/?)(\w*)(\/?)(.*)/g
|
|
174
|
+
const pullHashAndSlashFromPath = (str) => str.replace(/^(#\/?)(.*)/, '$2')
|
|
175
|
+
const pullSlashFromPath = (str) => str.replace(/^(\/?)(.*)/, '$2')
|
|
176
|
+
const pullMainRoute = (str) => str.replace(routeRE, '$2')
|
|
177
|
+
const pullParams = (str) => str.replace(routeRE, '$4')
|
|
178
|
+
const pullTranslateX = str => str.replace(/^(matrix)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*)(,.*)/, '$6')
|
|
179
|
+
const pullTranslateY = str => str.replace(/^(matrix)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d)(.*)/, '$7')
|
|
180
|
+
const pullTranslateYFromHeader = str => str.replace(/^(transform: matrix)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*,)(.*\d*)(\).*;)/, '$6')
|
|
181
|
+
export { getConstructorName, arrFromMapKeys, getAllMethodNames, findStrOrRegexMatchStr, findStrFromRegexArr, checkIfObjIsNotEmptyOrNil, isIOS, pullRouteInfo, pullTranslateYFromHeader, pullSlashFromPath, pullHashAndSlashFromPath, closest, pullTranslateY, pullTranslateX, pullMainRoute, pullParams, right, left, fromNullable, findInObj, ifNilThenUpdate, removeSlashes, subscribeFn, convertDomStringMapToObj, delayCall }
|