spyne 0.14.8 → 0.17.3
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/.travis.yml +2 -2
- package/karma.conf.js +27 -20
- package/lib/channel-action-filter.test.2418910233.js +20 -0
- package/lib/channel-dom.test.1490741340.js +20 -0
- package/lib/channel-fetch-util.test.3681936279.js +20 -0
- package/lib/channel-fetch.test.380764798.js +20 -0
- package/lib/channel-payload-class.test.2325155642.js +20 -0
- package/lib/channel-payload-filter.test.1598505124.js +20 -0
- package/lib/channel-route.test.921296320.js +20 -0
- package/lib/channel-stream-item.test.159699696.js +20 -0
- package/lib/channel-ui.test.291129654.js +20 -0
- package/lib/channel-util-dom.test.181212370.js +20 -0
- package/lib/channel.test.706832124.js +20 -0
- package/lib/commons.js +50363 -0
- package/lib/dom-el-selectors.test.3296414834.js +20 -0
- package/lib/dom-el-template.test.1459850380.js +20 -0
- package/lib/dom-el.test.2449130808.js +20 -0
- package/lib/frp-tools.test.1620088187.js +20 -0
- package/lib/import.test.723835576.js +20 -0
- package/lib/index.test.2146503294.js +20 -0
- package/lib/plugins-methods.test.3482246428.js +20 -0
- package/lib/route-utils.test.2932649409.js +20 -0
- package/lib/runtime.js +174 -0
- package/lib/spyne-app-properties.test.485192211.js +20 -0
- package/lib/spyne-app.test.4150724251.js +20 -0
- package/lib/spyne-plugin.test.3993976219.js +20 -0
- package/lib/spyne.js +15477 -18467
- package/lib/spyne.min.js +2 -12
- package/lib/spyne.min.js.LICENSE.txt +10 -0
- package/lib/url-utils.test.3668806082.js +20 -0
- package/lib/view-stream-broadcaster.test.2534955231.js +20 -0
- package/lib/view-stream-enhancer-loader.test.3395418180.js +20 -0
- package/lib/view-stream-enhancer.test.1043626253.js +20 -0
- package/lib/view-stream.test.1765314964.js +20 -0
- package/package.json +37 -65
- package/src/spyne/channels/channel-fetch-class.js +24 -1
- package/src/spyne/channels/channel-payload-class.js +102 -11
- package/src/spyne/channels/channel-proxy.js +6 -4
- package/src/spyne/channels/channel.js +66 -6
- package/src/spyne/channels/channels-config.js +2 -2
- package/src/spyne/channels/{channels-delegator.js → channels-map.js} +37 -21
- package/src/spyne/channels/spyne-channel-lifecycle.js +1 -1
- package/src/spyne/channels/spyne-channel-route.js +95 -15
- package/src/spyne/channels/spyne-channel-ui.js +1 -0
- package/src/spyne/channels/spyne-channel-window.js +60 -20
- package/src/spyne/spyne-app.js +181 -0
- package/src/spyne/spyne-plugins.js +146 -0
- package/src/spyne/spyne.js +11 -139
- package/src/spyne/utils/channel-fetch-util.js +1 -1
- package/src/spyne/utils/channel-payload-filter.js +166 -30
- package/src/spyne/utils/frp-tools.js +21 -1
- package/src/spyne/utils/mixins/base-streams-mixins.js +1 -0
- package/src/spyne/utils/spyne-app-properties.js +213 -0
- package/src/spyne/utils/spyne-logger.js +18 -0
- package/src/spyne/utils/spyne-plugins-methods.js +105 -0
- package/src/spyne/utils/spyne-scroll-lock.js +95 -0
- package/src/spyne/utils/spyne-utils-channel-route-url.js +2 -1
- package/src/spyne/utils/spyne-utils-channel-route.js +3 -1
- package/src/spyne/utils/spyne-utils-channel-window.js +2 -2
- package/src/spyne/views/dom-element-template.js +52 -23
- package/src/spyne/views/dom-element.js +11 -2
- package/src/spyne/views/view-stream-broadcaster.js +3 -3
- package/src/spyne/views/view-stream-payload.js +76 -15
- package/src/spyne/views/view-stream-selector.js +2 -2
- package/src/spyne/views/view-stream.js +219 -115
- package/src/tests/channels/channel-fetch.test.js +102 -0
- package/src/tests/channels/channel-payload-class.test.js +149 -0
- package/src/tests/channels/channel-payload-filter.test.js +298 -0
- package/src/tests/channels/channel-route.test.js +76 -1
- package/src/tests/channels/channel-stream-item.test.js +3 -2
- package/src/tests/channels/channel.test.js +38 -0
- package/src/tests/channels/route-utils.test.js +1 -1
- package/src/tests/index.js +0 -1
- package/src/tests/index.test.js +6 -0
- package/src/tests/mocks/channel-payload-data.js +93 -1
- package/src/tests/mocks/msf-user-data-small.json +4103 -0
- package/src/tests/mocks/msf-user-data.json +47035 -0
- package/src/tests/mocks/utils-data.js +20 -2
- package/src/tests/spyne-app.test.js +27 -0
- package/src/tests/spyne-plugin.test.js +49 -0
- package/src/tests/utils/channel-action-filter.test.js +22 -11
- package/src/tests/utils/channel-data-packet-generator.unused.js +119 -0
- package/src/tests/utils/plugins-methods.test.js +103 -0
- package/src/tests/utils/spyne-app-properties.test.js +11 -0
- package/src/tests/views/dom-el-selectors.test.js +1 -1
- package/webpack.config.js +30 -15
- package/lib/spyne.js.map +0 -1
- package/src/spyne/utils/viewstream-dom-utils.js +0 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spyne",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.3",
|
|
5
5
|
"description": "Reactive Real-DOM Framework for Advanced Javascript applications",
|
|
6
6
|
"main": "lib/spyne.min.js",
|
|
7
7
|
"module": "src/spyne/spyne.js",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"eslint-fix-tests": "eslint --fix 'src/tests/**'",
|
|
12
12
|
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
13
13
|
"commit": "git-cz",
|
|
14
|
-
"build": "webpack --mode production --env build
|
|
14
|
+
"build": "webpack --mode production --env build ",
|
|
15
15
|
"start": "webpack-dev-server --hot ",
|
|
16
|
-
"dev": "webpack --mode development --progress
|
|
16
|
+
"dev": "webpack --mode development --progress --watch --env dev ",
|
|
17
17
|
"stats": "webpack --profile --json --optimize-minimize --mode production --env build > stats.json",
|
|
18
18
|
"docs": "jsdoc --readme README.md -d docs -c docs/jsdoc.config.json -r",
|
|
19
19
|
"esdocs": "esdoc -d esdocs -c esdocs/esdoc.config.json -r",
|
|
@@ -30,68 +30,42 @@
|
|
|
30
30
|
"author": "Frank Batista",
|
|
31
31
|
"license": "LGPL",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "^7.
|
|
34
|
-
"@babel/
|
|
35
|
-
"babel-
|
|
36
|
-
"
|
|
37
|
-
"chai
|
|
38
|
-
"
|
|
33
|
+
"@babel/core": "^7.15.0",
|
|
34
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
|
35
|
+
"@babel/preset-env": "^7.15.0",
|
|
36
|
+
"babel-loader": "^8.2.2",
|
|
37
|
+
"chai": "^4.3.4",
|
|
38
|
+
"chai-dom": "^1.9.0",
|
|
39
39
|
"clean-webpack-plugin": "^3.0.0",
|
|
40
|
-
"commitizen": "^4.2.
|
|
41
|
-
"css-loader": "^
|
|
42
|
-
"cz-conventional-changelog": "^3.0
|
|
43
|
-
"
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"eslint-config-
|
|
46
|
-
"eslint-
|
|
47
|
-
"eslint-
|
|
48
|
-
"eslint-plugin-
|
|
49
|
-
"eslint-plugin-
|
|
50
|
-
"eslint-plugin-
|
|
51
|
-
"
|
|
52
|
-
"expect": "^24.9.0",
|
|
53
|
-
"file-loader": "^4.2.0",
|
|
54
|
-
"fstream": "^1.0.12",
|
|
40
|
+
"commitizen": "^4.2.4",
|
|
41
|
+
"css-loader": "^6.2.0",
|
|
42
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
43
|
+
"eslint": "^7.32.0",
|
|
44
|
+
"eslint-config-semistandard": "^16.0.0",
|
|
45
|
+
"eslint-config-standard": "^16.0.3",
|
|
46
|
+
"eslint-loader": "^4.0.2",
|
|
47
|
+
"eslint-plugin-import": "^2.24.2",
|
|
48
|
+
"eslint-plugin-node": "^11.1.0",
|
|
49
|
+
"eslint-plugin-promise": "^5.1.0",
|
|
50
|
+
"eslint-plugin-standard": "^5.0.0",
|
|
51
|
+
"file-loader": "^6.2.0",
|
|
55
52
|
"ghooks": "^2.0.4",
|
|
56
|
-
"
|
|
57
|
-
"immutable": "^3.8.2",
|
|
58
|
-
"istanbul": "^0.4.5",
|
|
59
|
-
"jsdoc": "^3.6.3",
|
|
60
|
-
"json-loader": "^0.5.7",
|
|
61
|
-
"karma": "^4.2.0",
|
|
53
|
+
"karma": "^6.3.4",
|
|
62
54
|
"karma-chai": "^0.1.0",
|
|
63
55
|
"karma-chrome-launcher": "^3.1.0",
|
|
64
|
-
"karma-coverage": "^
|
|
65
|
-
"karma-
|
|
66
|
-
"karma-
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"predicado": "0.0.6",
|
|
78
|
-
"preload-image-loader": "^1.0.0",
|
|
79
|
-
"resolve-url-loader": "^3.1.2",
|
|
80
|
-
"rimraf": "^3.0.0",
|
|
81
|
-
"selenium-webdriver": "^4.0.0-alpha.1",
|
|
82
|
-
"semistandard": "^13.0.1",
|
|
83
|
-
"tar": "^4.4.10",
|
|
84
|
-
"url-loader": "^2.1.0",
|
|
85
|
-
"webpack": "^4.39.2",
|
|
86
|
-
"webpack-bundle-analyzer": "^3.4.1",
|
|
87
|
-
"webpack-cli": "^3.3.6",
|
|
88
|
-
"webpack-dev-middleware": "^3.7.0",
|
|
89
|
-
"webpack-dev-server": "^3.11.2",
|
|
90
|
-
"webpack-merge": "^4.2.1",
|
|
91
|
-
"webpack-node-externals": "^1.7.2",
|
|
92
|
-
"webpack-rxjs-externals": "^2.0.0",
|
|
93
|
-
"webpack-shell-plugin": "^0.5.0",
|
|
94
|
-
"yargs": "13.3.0"
|
|
56
|
+
"karma-coverage": "^2.0.3",
|
|
57
|
+
"karma-mocha": "^2.0.1",
|
|
58
|
+
"karma-webpack": "^5.0.0",
|
|
59
|
+
"mocha": "^9.1.1",
|
|
60
|
+
"mocha-loader": "^5.1.5",
|
|
61
|
+
"selenium-webdriver": "^4.0.0-beta.4",
|
|
62
|
+
"tslib": "^2.3.1",
|
|
63
|
+
"webpack": "^5.51.1",
|
|
64
|
+
"webpack-cli": "^4.8.0",
|
|
65
|
+
"webpack-dev-middleware": "^5.0.0",
|
|
66
|
+
"webpack-dev-server": "^4.0.0",
|
|
67
|
+
"webpack-node-externals": "^3.0.0",
|
|
68
|
+
"webpack-rxjs-externals": "^2.0.0"
|
|
95
69
|
},
|
|
96
70
|
"config": {
|
|
97
71
|
"ghooks": {
|
|
@@ -102,9 +76,7 @@
|
|
|
102
76
|
}
|
|
103
77
|
},
|
|
104
78
|
"dependencies": {
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"rxjs": "^6.5.2",
|
|
108
|
-
"spynejs-polyfill": "0.0.4"
|
|
79
|
+
"ramda": "^0.27.1",
|
|
80
|
+
"rxjs": "^7.3.0"
|
|
109
81
|
}
|
|
110
82
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Channel } from './channel';
|
|
2
2
|
import { ChannelFetchUtil } from '../utils/channel-fetch-util';
|
|
3
|
-
import {path, pick, mergeDeepRight, defaultTo, reject, compose, isNil} from 'ramda';
|
|
3
|
+
import {path, pick, mergeDeepRight, all, allPass, either, values, defaultTo, reject, compose, isNil} from 'ramda';
|
|
4
4
|
|
|
5
5
|
export class ChannelFetch extends Channel {
|
|
6
6
|
/**
|
|
@@ -50,7 +50,11 @@ export class ChannelFetch extends Channel {
|
|
|
50
50
|
constructor(name, props = {}) {
|
|
51
51
|
|
|
52
52
|
// ALLOW FOR GENERIC MAP PROPERTY
|
|
53
|
+
|
|
54
|
+
ChannelFetch.validateMapMethod(props, name);
|
|
55
|
+
|
|
53
56
|
if (props.map!==undefined){
|
|
57
|
+
|
|
54
58
|
props.mapFn = props.map;
|
|
55
59
|
}
|
|
56
60
|
props.extendedActionsArr = [
|
|
@@ -61,6 +65,25 @@ export class ChannelFetch extends Channel {
|
|
|
61
65
|
super(name, props);
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
static validateMapMethod(props, name, testMode=false){
|
|
69
|
+
const isNotEmpty = arr=>arr.length>=1
|
|
70
|
+
const isNotFunction = val => typeof(val)!=='function';
|
|
71
|
+
const isUndefinedOrWrongType = either(isNil, isNotFunction)
|
|
72
|
+
const isUndefined = all(isUndefinedOrWrongType);
|
|
73
|
+
const isNotUndefinedAndIsNotEmpty = allPass([isUndefined, isNotEmpty])
|
|
74
|
+
const mapMethodIsInvalid = compose(isNotUndefinedAndIsNotEmpty,values, pick(['map', 'mapFn']))(props)
|
|
75
|
+
|
|
76
|
+
if (mapMethodIsInvalid){
|
|
77
|
+
if(testMode===false) {
|
|
78
|
+
console.warn(`Spyne Warning: The map method for ChannelFetch, ${name}, appears to be invalid`);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return true;
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
64
87
|
onRegistered() {
|
|
65
88
|
this.startFetch();
|
|
66
89
|
}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
mergeAll,
|
|
3
|
+
clone,
|
|
4
|
+
fromPairs,
|
|
5
|
+
toPairs,
|
|
6
|
+
compose,
|
|
7
|
+
mergeDeepRight,
|
|
8
|
+
mergeRight,
|
|
9
|
+
pathEq,
|
|
10
|
+
includes,
|
|
11
|
+
pickAll,
|
|
12
|
+
__,
|
|
13
|
+
lte, defaultTo, prop, is, mapObjIndexed,
|
|
14
|
+
} from 'ramda';
|
|
15
|
+
import {SpyneAppProperties} from '../utils/spyne-app-properties';
|
|
2
16
|
|
|
3
17
|
export class ChannelPayload {
|
|
4
18
|
/**
|
|
@@ -21,12 +35,18 @@ export class ChannelPayload {
|
|
|
21
35
|
* @property {UIEvent} event - = undefined; The UIEvent, if any.
|
|
22
36
|
* @returns Validated ChannelPayload json object
|
|
23
37
|
*/
|
|
24
|
-
constructor(channelName, action, payload, srcElement, event) {
|
|
38
|
+
constructor(channelName, action, payload, srcElement, event, timeLabel) {
|
|
25
39
|
let channel = channelName;
|
|
40
|
+
//payload = ChannelPayload.deepFreeze(payload);
|
|
26
41
|
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
if(timeLabel){
|
|
43
|
+
console.time(timeLabel);
|
|
44
|
+
}
|
|
29
45
|
|
|
46
|
+
let channelPayloadItemObj = { channelName, action, srcElement, event };
|
|
47
|
+
// Object.defineProperty(channelPayloadItemObj, 'payload', {get: () => clone(payload)});
|
|
48
|
+
const frozenPayload = ChannelPayload.deepFreeze(payload);
|
|
49
|
+
channelPayloadItemObj['payload'] = frozenPayload;
|
|
30
50
|
/**
|
|
31
51
|
* This is a convenience method that helps with destructuring by merging all properties.
|
|
32
52
|
*
|
|
@@ -40,34 +60,68 @@ export class ChannelPayload {
|
|
|
40
60
|
*
|
|
41
61
|
*/
|
|
42
62
|
|
|
43
|
-
const isDebugMode = pathEq(['Spyne','config', 'debug'], true)(window);
|
|
44
63
|
|
|
45
|
-
|
|
64
|
+
|
|
65
|
+
if (SpyneAppProperties.debug === true){
|
|
46
66
|
if (payload.hasOwnProperty('payload')){
|
|
47
67
|
let payloadStr = JSON.stringify(payload);
|
|
48
68
|
console.warn(`Spyne Warning: the following payload contains a nested payload property which may create conflicts: Action: ${action}, ${payloadStr}`);
|
|
49
69
|
}
|
|
70
|
+
|
|
71
|
+
const channelActionsArr = SpyneAppProperties.getChannelActions(channel);
|
|
72
|
+
|
|
73
|
+
ChannelPayload.validateAction(action, channel, channelActionsArr);
|
|
74
|
+
|
|
75
|
+
|
|
50
76
|
}
|
|
51
77
|
|
|
52
78
|
|
|
53
79
|
|
|
54
|
-
|
|
80
|
+
/* channelPayloadItemObj.props = () => clone(mergeAll([
|
|
81
|
+
{payload:ChannelPayload.deepClone(channelPayloadItemObj.payload)},
|
|
82
|
+
channelPayloadItemObj.payload,
|
|
83
|
+
{ channel },
|
|
84
|
+
{ event: event },
|
|
85
|
+
{srcElement: srcElement},
|
|
86
|
+
channelPayloadItemObj.srcElement, {
|
|
87
|
+
action: channelPayloadItemObj.action }
|
|
88
|
+
]));
|
|
89
|
+
*/
|
|
55
90
|
|
|
56
91
|
|
|
57
|
-
const
|
|
92
|
+
const channelPayloadItemObjProps = {
|
|
93
|
+
$dir: {
|
|
94
|
+
get: () => channelPayloadItemObj._dir,
|
|
95
|
+
set: (val) => channelPayloadItemObj._dir=val
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
58
99
|
|
|
59
|
-
ChannelPayload.validateAction(action, channel, channelActionsArr);
|
|
60
100
|
|
|
61
101
|
if (channel === 'CHANNEL_ROUTE') {
|
|
62
|
-
channelPayloadItemObj['location'] = ChannelPayload.getLocationData();
|
|
102
|
+
//channelPayloadItemObj['location'] = ChannelPayload.getLocationData();
|
|
103
|
+
channelPayloadItemObjProps['location'] = {
|
|
104
|
+
get: ()=>ChannelPayload.getLocationData()
|
|
105
|
+
}
|
|
106
|
+
/* channelPayloadItemObjProps['routeData'] = {
|
|
107
|
+
get: ()=>prop('routeData', frozenPayload)
|
|
108
|
+
}
|
|
109
|
+
*/
|
|
63
110
|
}
|
|
64
111
|
|
|
112
|
+
channelPayloadItemObj._dir = undefined;
|
|
113
|
+
|
|
114
|
+
Object.defineProperties(channelPayloadItemObj, channelPayloadItemObjProps)
|
|
115
|
+
|
|
116
|
+
if(timeLabel){
|
|
117
|
+
console.timeEnd(timeLabel);
|
|
118
|
+
}
|
|
65
119
|
return channelPayloadItemObj;
|
|
66
120
|
}
|
|
67
121
|
|
|
68
122
|
static validateAction(action, channel, arr) {
|
|
69
123
|
let isInArr = includes(action, arr);
|
|
70
|
-
if (isInArr === false &&
|
|
124
|
+
if (isInArr === false && SpyneAppProperties.initialized === true) {
|
|
71
125
|
console.warn(`warning: Action: '${action}' is not registered within the ${channel} channel!`);
|
|
72
126
|
}
|
|
73
127
|
return isInArr;
|
|
@@ -91,6 +145,43 @@ export class ChannelPayload {
|
|
|
91
145
|
|
|
92
146
|
}
|
|
93
147
|
|
|
148
|
+
static deepClone(o) {
|
|
149
|
+
const isArr = is(Array);
|
|
150
|
+
const isObj = is(Object);
|
|
151
|
+
const isIter = ob => isArr(ob)===false && isObj(ob)===true;
|
|
152
|
+
const isIterable = isIter(o);
|
|
153
|
+
return isIterable ? compose(fromPairs, toPairs, clone)(o) : clone(o);
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
static deepFreeze(o) {
|
|
160
|
+
//return o;
|
|
161
|
+
//return Object.freeze(o);
|
|
162
|
+
const elIsDomElement = compose(lte(0), defaultTo(-1), prop('nodeType'));
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
Object.freeze(o);
|
|
166
|
+
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
167
|
+
if (o.hasOwnProperty(prop)
|
|
168
|
+
&& elIsDomElement(o[prop]) === false
|
|
169
|
+
&& o[prop] !== null
|
|
170
|
+
&& (typeof o[prop] === "object" || typeof o[prop] === "function")
|
|
171
|
+
&& !Object.isFrozen(o[prop])) {
|
|
172
|
+
ChannelPayload.deepFreeze(o[prop]);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
} catch(e){
|
|
177
|
+
//console.log("FREEZE ERR ",{o,e});
|
|
178
|
+
return o;
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return o;
|
|
183
|
+
}
|
|
184
|
+
|
|
94
185
|
static getMouseEventKeys() {
|
|
95
186
|
return ['altKey', 'bubbles', 'cancelBubble', 'cancelable', 'clientX', 'clientY', 'composed', 'ctrlKey', 'currentTarget', 'defaultPrevented', 'detail', 'eventPhase', 'fromElement', 'isTrusted', 'layerX', 'layerY', 'metaKey', 'movementX', 'movementY', 'offsetX', 'offsetY', 'pageX', 'pageY', 'path', 'relatedTarget', 'returnValue', 'screenX', 'screenY', 'shiftKey', 'sourceCapabilities', 'srcElement', 'target', 'timeStamp', 'toElement', 'type', 'view', 'which', 'x', 'y'];
|
|
96
187
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Channel } from './channel';
|
|
2
|
+
import {SpyneAppProperties} from '../utils/spyne-app-properties';
|
|
2
3
|
import { Subject, ReplaySubject, merge } from 'rxjs';
|
|
3
4
|
import {includes, path} from 'ramda';
|
|
5
|
+
import {delayCall} from '../utils/frp-tools';
|
|
4
6
|
|
|
5
7
|
export class ChannelProxy extends Channel {
|
|
6
8
|
/**
|
|
@@ -22,7 +24,7 @@ export class ChannelProxy extends Channel {
|
|
|
22
24
|
this.subject$ = new Subject();
|
|
23
25
|
this.replaySub$ = new ReplaySubject(1);
|
|
24
26
|
this.observer$ = merge(this.subject$, this.replaySub$);
|
|
25
|
-
const isDevMode =
|
|
27
|
+
const isDevMode = SpyneAppProperties.debug;
|
|
26
28
|
if (isDevMode === true){
|
|
27
29
|
this.checkIfChannelIsStillProxy(name);
|
|
28
30
|
}
|
|
@@ -36,14 +38,14 @@ export class ChannelProxy extends Channel {
|
|
|
36
38
|
let name = channelName;
|
|
37
39
|
|
|
38
40
|
const checkIfProxy=()=>{
|
|
39
|
-
|
|
40
|
-
let bool = includes(name, window.Spyne.channels.listRegisteredChannels());
|
|
41
|
+
let bool = includes(name, SpyneAppProperties.listRegisteredChannels());
|
|
41
42
|
if (bool!==true){
|
|
42
43
|
console.warn(`Spyne Warning: The channel, ${name} does not appear to be registered!`);
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
delayCall(checkIfProxy, 1000);
|
|
48
|
+
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
get replaySubject() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { registeredStreamNames } from './channels-config';
|
|
2
2
|
import { ChannelPayload } from './channel-payload-class';
|
|
3
3
|
import { ChannelPayloadFilter} from '../utils/channel-payload-filter';
|
|
4
|
+
import {SpyneAppProperties} from '../utils/spyne-app-properties';
|
|
4
5
|
import {RouteChannelUpdater} from '../utils/route-channel-updater';
|
|
5
6
|
import { ReplaySubject, Subject } from 'rxjs';
|
|
6
7
|
import {filter} from 'rxjs/operators';
|
|
@@ -18,8 +19,11 @@ import {
|
|
|
18
19
|
always,
|
|
19
20
|
fromPairs,
|
|
20
21
|
path,
|
|
22
|
+
assocPath,
|
|
23
|
+
isEmpty,
|
|
21
24
|
equals,
|
|
22
25
|
prop,
|
|
26
|
+
propEq,
|
|
23
27
|
apply,
|
|
24
28
|
} from 'ramda';
|
|
25
29
|
const rMap = require('ramda').map;
|
|
@@ -70,20 +74,28 @@ export class Channel {
|
|
|
70
74
|
this.addRegisteredActions.bind(this);
|
|
71
75
|
this.createChannelActionsObj(CHANNEL_NAME, props.extendedActionsArr);
|
|
72
76
|
props.name = CHANNEL_NAME;
|
|
77
|
+
props.defaultActions = props.data!==undefined ? [`${props.name}_EVENT`] : [];
|
|
73
78
|
this.props = props;
|
|
79
|
+
this.props.isRegistered = false;
|
|
74
80
|
this.props.isProxy = this.props.isProxy === undefined ? false : this.props.isProxy;
|
|
75
|
-
|
|
81
|
+
const defaultCachedPayloadBool = this.props['data']!==undefined;
|
|
82
|
+
this.props.sendCachedPayload = this.props.sendCachedPayload === undefined ? defaultCachedPayloadBool : this.props.sendCachedPayload;
|
|
76
83
|
this.sendPayloadToRouteChannel = new RouteChannelUpdater(this);
|
|
77
84
|
this.createChannelActionMethods();
|
|
78
|
-
this.streamsController =
|
|
85
|
+
this.streamsController = SpyneAppProperties.channelsMap;
|
|
79
86
|
let observer$ = this.getMainObserver();
|
|
80
|
-
|
|
87
|
+
this.checkForPersistentDataMode = Channel.checkForPersistentDataMode.bind(this);
|
|
81
88
|
this.observer$ = this.props['observer'] = observer$;
|
|
82
89
|
let dispatcherStream$ = this.streamsController.getStream('DISPATCHER');
|
|
83
|
-
|
|
90
|
+
const payloadPredByChannelName = propEq('name', props.name)
|
|
91
|
+
dispatcherStream$.pipe(filter(payloadPredByChannelName)).subscribe((val) => this.onReceivedObservable(val));
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
getMainObserver() {
|
|
95
|
+
if (this.streamsController === undefined){
|
|
96
|
+
console.warn(`Spyne Warning: The following channel, ${this.props.name}, appears to be registered before Spyne has been initialized.`)
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
let proxyExists = this.streamsController.testStream(this.props.name);
|
|
88
100
|
|
|
89
101
|
if (proxyExists === true) {
|
|
@@ -107,7 +119,13 @@ export class Channel {
|
|
|
107
119
|
* <p>This method is empty and is called as soon as the Channel has been registered.</p>
|
|
108
120
|
* <p>Tasks such as subscribing to other channels, and sending initial payloads can be added here.</p>
|
|
109
121
|
*/
|
|
110
|
-
onRegistered(){
|
|
122
|
+
onRegistered(props=this.props){
|
|
123
|
+
if(props.data!==undefined){
|
|
124
|
+
const action = Object.keys(this.channelActions)[0];
|
|
125
|
+
//console.log("CHANNELS ACTIONS IS ",this.channelActions);
|
|
126
|
+
//Object(this.channelActions).keys[0];
|
|
127
|
+
this.sendChannelPayload(action, props.data);
|
|
128
|
+
}
|
|
111
129
|
|
|
112
130
|
}
|
|
113
131
|
|
|
@@ -149,7 +167,37 @@ export class Channel {
|
|
|
149
167
|
initializeStream() {
|
|
150
168
|
this.checkForTraits();
|
|
151
169
|
this.onChannelInitialized();
|
|
170
|
+
this.checkForPersistentDataMode();
|
|
152
171
|
this.onRegistered();
|
|
172
|
+
this.props.isRegistered = true;
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static checkForPersistentDataMode(props=this.props, actionsObj=this.channelActions){
|
|
178
|
+
const actionsObjIsEmpty = isEmpty(actionsObj);
|
|
179
|
+
const dataIsAdded = prop('data', props) !== undefined;
|
|
180
|
+
const autoSetToCachedPayload = actionsObjIsEmpty === true && dataIsAdded === true;
|
|
181
|
+
const setDefaultActionsObj = ()=>{
|
|
182
|
+
const {name} = props;
|
|
183
|
+
const actionStr = `${name}_EVENT`;
|
|
184
|
+
return {
|
|
185
|
+
[actionStr] : actionStr
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (autoSetToCachedPayload){
|
|
190
|
+
props.sendCachedPayload = true;
|
|
191
|
+
actionsObj = setDefaultActionsObj();
|
|
192
|
+
|
|
193
|
+
if (this.channelActions!==undefined){
|
|
194
|
+
this.channelActions = actionsObj;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
//console.log("PROPS IS ",{actionsObjIsEmpty, dataIsAdded, props, actionsObj}, this.channelActions)
|
|
200
|
+
return {props, actionsObj};
|
|
153
201
|
}
|
|
154
202
|
|
|
155
203
|
setTrace(bool) {
|
|
@@ -214,7 +262,11 @@ export class Channel {
|
|
|
214
262
|
*
|
|
215
263
|
*/
|
|
216
264
|
addRegisteredActions() {
|
|
217
|
-
|
|
265
|
+
let arr = []
|
|
266
|
+
if (path(['props','data'], this)){
|
|
267
|
+
arr = [`${this.props.name}_EVENT`];
|
|
268
|
+
}
|
|
269
|
+
return arr;
|
|
218
270
|
}
|
|
219
271
|
|
|
220
272
|
onReceivedObservable(obj) {
|
|
@@ -222,6 +274,7 @@ export class Channel {
|
|
|
222
274
|
}
|
|
223
275
|
|
|
224
276
|
getActionMethodForObservable(obj) {
|
|
277
|
+
obj.unpacked=true;
|
|
225
278
|
const defaultFn = this.onViewStreamInfo.bind(this);
|
|
226
279
|
|
|
227
280
|
let methodStr = path(['data', 'action'], obj);
|
|
@@ -306,9 +359,14 @@ export class Channel {
|
|
|
306
359
|
*/
|
|
307
360
|
sendChannelPayload(action, payload, srcElement = {}, event = {}, obs$ = this.observer$) {
|
|
308
361
|
// MAKES ALL CHANNEL BASE AND DATA STREAMS CONSISTENT
|
|
362
|
+
|
|
363
|
+
|
|
309
364
|
let channelPayloadItem = new ChannelPayload(this.props.name, action, payload, srcElement, event);
|
|
310
365
|
// console.log("CHANNEL STREEM ITEM ",channelPayloadItem);
|
|
311
366
|
|
|
367
|
+
// const onNextFrame = ()=>obs$.next(channelPayloadItem);
|
|
368
|
+
//requestAnimationFrame(onNextFrame)
|
|
369
|
+
|
|
312
370
|
obs$.next(channelPayloadItem);
|
|
313
371
|
}
|
|
314
372
|
|
|
@@ -354,6 +412,7 @@ export class Channel {
|
|
|
354
412
|
*
|
|
355
413
|
*/
|
|
356
414
|
|
|
415
|
+
/*
|
|
357
416
|
setTimeout(fn, ms=0, bind=false){
|
|
358
417
|
const timeoutMethod = (...args)=>{
|
|
359
418
|
if (this!==undefined && this.props!==undefined){
|
|
@@ -363,6 +422,7 @@ export class Channel {
|
|
|
363
422
|
}
|
|
364
423
|
window.setTimeout(timeoutMethod, ms);
|
|
365
424
|
}
|
|
425
|
+
*/
|
|
366
426
|
|
|
367
427
|
|
|
368
428
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// import Spyne from '../spyne';
|
|
2
2
|
import { arrFromMapKeys } from '../utils/frp-tools';
|
|
3
|
-
|
|
3
|
+
import {SpyneAppProperties} from '../utils/spyne-app-properties';
|
|
4
4
|
import {compose, path, is} from 'ramda';
|
|
5
5
|
const Observable = require('rxjs');
|
|
6
6
|
const Subject = require('rxjs');
|
|
7
7
|
|
|
8
8
|
// console.log('channels config loaded ',R,Rx);
|
|
9
9
|
let registeredStreamNames = () => ({
|
|
10
|
-
includes: () =>
|
|
10
|
+
includes: () => SpyneAppProperties.initialized === true ? SpyneAppProperties.listRegisteredChannels() : ['CHANNEL_ROUTE', 'CHANNEL_UI', 'CHANNEL_WINDOW', 'DISPATCHER']
|
|
11
11
|
|
|
12
12
|
});
|
|
13
13
|
|