spyne 0.18.2 → 0.19.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spyne",
3
3
  "sideEffects": false,
4
- "version": "0.18.2",
4
+ "version": "0.19.0",
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",
@@ -28,55 +28,40 @@
28
28
  },
29
29
  "keywords": [],
30
30
  "author": "Frank Batista",
31
- "license": "LGPL",
31
+ "license": "UNLICENSED",
32
32
  "devDependencies": {
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
- "clean-webpack-plugin": "^3.0.0",
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",
33
+ "chai": "^4.3.9",
34
+ "chai-dom": "^1.11.0",
35
+ "clean-webpack-plugin": "^4.0.0",
36
+ "css-loader": "^6.8.1",
37
+ "eslint": "^8.50.0",
38
+ "eslint-config-semistandard": "^17.0.0",
39
+ "eslint-config-standard": "^17.1.0",
40
+ "eslint-plugin-import": "^2.28.1",
48
41
  "eslint-plugin-node": "^11.1.0",
49
- "eslint-plugin-promise": "^5.1.0",
42
+ "eslint-plugin-promise": "^6.1.1",
50
43
  "eslint-plugin-standard": "^5.0.0",
51
44
  "file-loader": "^6.2.0",
52
- "ghooks": "^2.0.4",
53
- "karma": "^6.3.4",
45
+ "karma": "^6.4.2",
54
46
  "karma-chai": "^0.1.0",
55
- "karma-chrome-launcher": "^3.1.0",
56
- "karma-coverage": "^2.0.3",
47
+ "karma-chrome-launcher": "^3.2.0",
48
+ "karma-coverage": "^2.2.1",
57
49
  "karma-mocha": "^2.0.1",
58
50
  "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",
51
+ "mocha": "^10.2.0",
52
+ "webpack": "^5.88.2",
53
+ "webpack-cli": "^5.1.4",
54
+ "webpack-dev-middleware": "^6.1.1",
55
+ "webpack-dev-server": "^4.15.1",
68
56
  "webpack-rxjs-externals": "^2.0.0"
69
57
  },
70
58
  "config": {
71
59
  "ghooks": {
72
60
  "pre-commit": "npm run test:single"
73
- },
74
- "commitizen": {
75
- "path": "cz-conventional-changelog"
76
61
  }
77
62
  },
78
63
  "dependencies": {
79
- "ramda": "^0.27.1",
80
- "rxjs": "^7.3.0"
64
+ "ramda": "^0.29.0",
65
+ "rxjs": "^7.8.1"
81
66
  }
82
67
  }
@@ -100,7 +100,7 @@ export class ChannelFetch extends Channel {
100
100
 
101
101
  startFetch(options = {}, subscriber = this.onFetchReturned.bind(this)) {
102
102
  let fetchProps = this.consolidateAllFetchProps(options);
103
- return new ChannelFetchUtil(fetchProps, subscriber);
103
+ return new ChannelFetchUtil(fetchProps, subscriber, false, this.props.name);
104
104
  }
105
105
 
106
106
  onFetchUpdate(evt) {
@@ -113,7 +113,9 @@ export class ChannelFetch extends Channel {
113
113
  }
114
114
 
115
115
  createChannelPayloadItem(payload, action = `${this.props.name}_DATA_EVENT`) {
116
- this.sendChannelPayload(action, payload);
116
+ const {name, sendCachedPayload, url} = this.props;
117
+ const srcElement = {name, sendCachedPayload, url};
118
+ this.sendChannelPayload(action, payload, srcElement);
117
119
  }
118
120
 
119
121
  getPropsForFetch(evt) {
@@ -12,6 +12,7 @@ import {
12
12
  is
13
13
  } from 'ramda';
14
14
  import {SpyneAppProperties} from '../utils/spyne-app-properties';
15
+ import {safeClone} from '../utils/safe-clone';
15
16
 
16
17
  export class ChannelPayload {
17
18
  /**
@@ -76,15 +77,15 @@ export class ChannelPayload {
76
77
 
77
78
 
78
79
 
79
- channelPayloadItemObj.clone = () => clone(mergeAll([
80
- {payload:ChannelPayload.deepClone(channelPayloadItemObj.payload)},
80
+ channelPayloadItemObj.clone = () => mergeAll([
81
+ {payload:safeClone(channelPayloadItemObj.payload)},
81
82
  channelPayloadItemObj.payload,
82
- { channel },
83
- { event: event },
83
+ { channel: clone(channel) },
84
+ { event: clone(event) },
84
85
  {srcElement: srcElement},
85
- channelPayloadItemObj.srcElement, {
86
- action: channelPayloadItemObj.action }
87
- ]));
86
+ clone(channelPayloadItemObj.srcElement), {
87
+ action: clone(channelPayloadItemObj.action) }
88
+ ]);
88
89
 
89
90
 
90
91
 
@@ -84,7 +84,7 @@ export class Channel {
84
84
  this.checkForPersistentDataMode = Channel.checkForPersistentDataMode.bind(this);
85
85
  this.observer$ = this.props['observer'] = observer$;
86
86
  let dispatcherStream$ = this.streamsController.getStream('DISPATCHER');
87
- const payloadPredByChannelName = propEq('name', props.name)
87
+ const payloadPredByChannelName = propEq(props.name, 'name')
88
88
  dispatcherStream$.pipe(filter(payloadPredByChannelName)).subscribe((val) => this.onReceivedObservable(val));
89
89
  }
90
90
 
@@ -295,7 +295,7 @@ export class Channel {
295
295
  //console.log("INCOMING ",{action, payload, srcElement}, {obj});
296
296
  const mergeProps = (d) => mergeAll([d, { action: prop('action', d) }, prop('payload', d), prop('srcElement', d)]);
297
297
  let dataObj = obsVal => ({
298
- props: () => mergeProps(obj.data),
298
+ clone: () => mergeProps(obj.data),
299
299
  action, payload, srcElement,
300
300
  event: obsVal
301
301
  });
@@ -401,6 +401,13 @@ export class Channel {
401
401
  }
402
402
 
403
403
 
404
+ static checkForNotTrackFlag(props={}){
405
+ if (props.doNotTrack === true){
406
+ SpyneAppProperties.doNotTrackChannel(props.channelName);
407
+ }
408
+
409
+
410
+ }
404
411
 
405
412
 
406
413
 
@@ -45,8 +45,8 @@ export class ChannelsMap {
45
45
 
46
46
  static listRegisteredChannels(showOnlyProxies = false) {
47
47
  let proxyMap = this.getChannelsList();
48
- let rejectProxyFn = reject(propEq('val', 'ChannelProxy'));
49
- let filterProxyFn = filter(propEq('val', 'ChannelProxy'));
48
+ let rejectProxyFn = reject(propEq('ChannelProxy', 'val'));
49
+ let filterProxyFn = filter(propEq('ChannelProxy', 'val' ));
50
50
  let fn = showOnlyProxies === true ? filterProxyFn : rejectProxyFn;
51
51
  let removedProxyArr = fn(proxyMap);
52
52
  return pluck(['key'], removedProxyArr);
@@ -57,7 +57,7 @@ export class ChannelsMap {
57
57
 
58
58
  checkForMissingChannels() {
59
59
  let proxyMap = this.getChannelsList();
60
- let filterProxyFn = filter(propEq('val', 'ChannelProxy'));
60
+ let filterProxyFn = filter(propEq('ChannelProxy', 'val'));
61
61
  let filterProxyArr = filterProxyFn(proxyMap);
62
62
 
63
63
  if (filterProxyArr.length >= 1) {
@@ -295,9 +295,18 @@ export class SpyneChannelWindow extends Channel {
295
295
  'CHANNEL_WINDOW_FOCUS_EVENT',
296
296
  'CHANNEL_WINDOW_FULLSCREENCHANGE_EVENT',
297
297
  'CHANNEL_WINDOW_FULLSCREENERROR_EVENT',
298
+ 'CHANNEL_WINDOW_KEYUP_EVENT',
299
+ 'CHANNEL_WINDOW_KEYDOWN_EVENT',
298
300
  'CHANNEL_WINDOW_LOAD_EVENT',
299
301
  'CHANNEL_WINDOW_MEDIA_QUERY_EVENT',
300
302
  'CHANNEL_WINDOW_MESSAGE_EVENT',
303
+ 'CHANNEL_WINDOW_MOUSEDOWN_EVENT',
304
+ 'CHANNEL_WINDOW_MOUSEENTER_EVENT',
305
+ 'CHANNEL_WINDOW_MOUSELEAVE_EVENT',
306
+ 'CHANNEL_WINDOW_MOUSEMOVE_EVENT',
307
+ 'CHANNEL_WINDOW_MOUSEOUT_EVENT',
308
+ 'CHANNEL_WINDOW_MOUSEOVER_EVENT',
309
+ 'CHANNEL_WINDOW_MOUSEUP_EVENT',
301
310
  'CHANNEL_WINDOW_MOUSEWHEEL_EVENT',
302
311
  'CHANNEL_WINDOW_OFFLINE_EVENT',
303
312
  'CHANNEL_WINDOW_ONLINE_EVENT',
@@ -3,7 +3,7 @@ import {ViewStream} from './views/view-stream';
3
3
  import {SpyneAppProperties} from './utils/spyne-app-properties';
4
4
  import {deepMerge} from './utils/deep-merge';
5
5
  const _channels = new ChannelsMap();
6
- const version = '0.18.2';
6
+ const version = '0.19.0';
7
7
 
8
8
  class SpyneApplication {
9
9
  /**
@@ -41,7 +41,7 @@ class SpyneApplication {
41
41
  init(config = {}, testMode=false) {
42
42
  //this.channels = new ChannelsMap();
43
43
  /*!
44
- * Spyne 0.18.2
44
+ * Spyne 0.19.0
45
45
  * https://spynejs.org
46
46
  *
47
47
  * @license Copyright 2017-2021, Frank Batista, Relevant Context, LLC. All rights reserved.
@@ -102,8 +102,8 @@ class SpyneApplication {
102
102
  };
103
103
  if (config !== undefined) {
104
104
  config = SpyneAppProperties.initialize(defaultConfig, config, _channels);
105
- window.Spyne = this;
106
- window.Spyne['config'] = deepMerge(defaultConfig, config)
105
+ //window.Spyne = this;
106
+ //window.Spyne['config'] = deepMerge(defaultConfig, config)
107
107
  }
108
108
 
109
109
  this.pluginsFn = SpyneAppProperties.getPluginsMethodObj(config['pluginMethods']);
@@ -117,7 +117,7 @@ class SpyneApplication {
117
117
  _channels.init();
118
118
 
119
119
  if (SpyneAppProperties.config.debug===true){
120
- //window.Spyne = {version};
120
+ window.Spyne = {version};
121
121
  }
122
122
 
123
123
 
@@ -14,6 +14,7 @@ import { ChannelPayload } from './channels/channel-payload-class';
14
14
  import {ChannelPayloadFilter} from './utils/channel-payload-filter';
15
15
  import {SpynePlugin} from './spyne-plugins';
16
16
  import { deepMerge } from './utils/deep-merge';
17
+ import {safeClone} from './utils/safe-clone';
17
18
  import {SpyneAppProperties} from './utils/spyne-app-properties';
18
19
  import {SpyneApp} from './spyne-app';
19
20
 
@@ -35,5 +36,6 @@ export {
35
36
  SpyneApp,
36
37
  SpyneAppProperties,
37
38
  SpynePlugin,
38
- deepMerge
39
+ deepMerge,
40
+ safeClone
39
41
  };
@@ -47,7 +47,7 @@ export class ChannelFetchUtil {
47
47
  */
48
48
 
49
49
 
50
- constructor(options, subscriber, testMode) {
50
+ constructor(options, subscriber, testMode, CHANNEL_NAME) {
51
51
 
52
52
  const testSubscriber = (p) => console.log('FETCH RETURNED ', p);
53
53
 
@@ -57,6 +57,7 @@ export class ChannelFetchUtil {
57
57
  this._serverOptions = ChannelFetchUtil.setServerOptions(options);
58
58
  this._subscriber = subscriber !== undefined ? subscriber : testSubscriber;
59
59
  this.debug = options.debug !== undefined ? options.debug : false;
60
+ this.channelName = CHANNEL_NAME;
60
61
 
61
62
  let fetchProps = {
62
63
  mapFn: this.mapFn,
@@ -66,18 +67,27 @@ export class ChannelFetchUtil {
66
67
  debug: this.debug
67
68
  };
68
69
  if (testMode !== true) {
69
- ChannelFetchUtil.startWindowFetch(fetchProps, this._subscriber);
70
+ ChannelFetchUtil.startWindowFetch(fetchProps, this._subscriber, this.channelName);
70
71
  }
71
72
  }
72
73
 
73
- static startWindowFetch(props, subscriber) {
74
+ static startWindowFetch(props, subscriber, channelName) {
74
75
  let { mapFn, url, serverOptions, responseType, debug } = props;
75
- const tapLogDebug = p => console.log('DEBUG FETCH :', p);
76
+ const tapLogDebug = p => console.log('DEBUG FETCH :', p, {url, serverOptions, responseType, channelName});
76
77
  const tapLog = debug === true ? tapLogDebug : () => {};
77
78
 
79
+ const mapWrapper = (mapMethod)=>{
80
+ const metadata = {channelName, url, responseType, serverOptions}
81
+
82
+ return (data)=>{
83
+ return mapMethod(data, metadata);
84
+ }
85
+
86
+ }
87
+
78
88
  let response$ = from(window.fetch(url, serverOptions))
79
89
  .pipe(tap(tapLog), flatMap(r => from(r[responseType]())),
80
- map(mapFn),
90
+ map(mapWrapper(mapFn)),
81
91
  publish());
82
92
 
83
93
  response$.connect();
@@ -126,7 +136,7 @@ export class ChannelFetchUtil {
126
136
 
127
137
  static updateMethodWhenBodyExists(opts) {
128
138
  const hasBody = has('body');
129
- const methodIsGet = propEq('method', 'GET');
139
+ const methodIsGet = propEq('GET', 'method');
130
140
  const pred = allPass([hasBody, methodIsGet]);
131
141
  return when(pred, assoc('method', 'POST'))(opts);
132
142
  }
@@ -0,0 +1,85 @@
1
+ import {clone, compose, fromPairs, is, path, toPairs} from 'ramda';
2
+ import {SpyneAppProperties} from './spyne-app-properties';
3
+
4
+
5
+
6
+
7
+ const getPropType = (prp) => {
8
+ let type = typeof prp;
9
+ if (['number', 'boolean', 'string'].includes(type)){
10
+ type = 'primitive';
11
+ } else if (type==='object'){
12
+ if (Array.isArray(prp)){
13
+ type = 'array'
14
+ } else if (prp===null){
15
+ type = 'undefined';
16
+ }
17
+ }
18
+ return type;
19
+ }
20
+
21
+
22
+ const cmsDataReviveNestedProxyObj = (proxyObj, proxyReviverMethod) => {
23
+
24
+
25
+ const {__proxy__proxyName} = proxyObj;
26
+
27
+ if (__proxy__proxyName === undefined){
28
+ console.error('object is not proxy object ',proxyObj);
29
+ }
30
+
31
+ const cloneNestedProxyObj = (target, pathArr)=>{
32
+ const nestedProxyObj = path(pathArr, proxyObj);
33
+ const {__proxy__isProxy, __proxy__props} = nestedProxyObj;
34
+ return __proxy__isProxy ? proxyReviverMethod(target, __proxy__props) : target;
35
+ }
36
+
37
+
38
+ const rootObj = cloneNestedProxyObj(clone(proxyObj), []);
39
+
40
+
41
+ const proxyIterable = (iterObj, iterPath) => {
42
+ let dataPath = iterPath || [];
43
+ const loopObj = ([key, prop]) => {
44
+ const type = getPropType(prop);
45
+ const clonedPath = [...dataPath]
46
+ clonedPath.push(key);
47
+ if (type === 'object' || type==='array') {
48
+ iterObj[key] = cloneNestedProxyObj(prop, clonedPath);
49
+ proxyIterable(prop, clonedPath)
50
+ }
51
+ }
52
+ Object.entries(iterObj).forEach(loopObj);
53
+ }
54
+
55
+ proxyIterable(rootObj);
56
+ // console.timeEnd('proxify2');
57
+
58
+
59
+ return rootObj;
60
+
61
+
62
+ }
63
+
64
+
65
+
66
+
67
+ export const safeClone = function(o){
68
+ const {__proxy__proxyName} = o;
69
+ if (__proxy__proxyName!==undefined){
70
+ const proxyReviverMethod = SpyneAppProperties.getProxyReviver(__proxy__proxyName);
71
+ if (typeof proxyReviverMethod === 'function'){
72
+ return cmsDataReviveNestedProxyObj(o, proxyReviverMethod);
73
+ }
74
+ }
75
+
76
+ const isArr = is(Array);
77
+ const isObj = is(Object);
78
+ const isIter = ob => isArr(ob)===false && isObj(ob)===true;
79
+ const isIterable = isIter(o);
80
+ return isIterable ? compose(fromPairs, toPairs, clone)(o) : clone(o);
81
+
82
+
83
+
84
+
85
+ }
@@ -5,9 +5,11 @@ import {path} from 'ramda';
5
5
 
6
6
  let _config;
7
7
  let _channels;
8
- let _channelsMap
8
+ let _channelsMap;
9
9
  let _initialized = false;
10
10
  let _debug = true;
11
+ const _doNotTrackChannelsArr = [];
12
+ const _proxiesMap = new Map();;
11
13
 
12
14
  const _spynePluginMethods = new SpynePluginsMethods();
13
15
 
@@ -162,6 +164,27 @@ class SpyneAppPropertiesClass{
162
164
 
163
165
  }
164
166
 
167
+
168
+
169
+ doNotTrackChannel(channelName){
170
+ _doNotTrackChannelsArr.push(channelName);
171
+ }
172
+
173
+ getUntrackedChannelsList(){
174
+ return _doNotTrackChannelsArr;
175
+ }
176
+
177
+
178
+ registerProxyReviver(name, method){
179
+ _proxiesMap.set(name, method);
180
+ //console.log("REGISTERD PROXY REVIVER",_proxiesMap, _proxiesMap.get(name));
181
+
182
+ }
183
+
184
+ getProxyReviver(proxyName){
185
+ return _proxiesMap.get(proxyName);
186
+ }
187
+
165
188
  getPluginConfigByPluginName(pluginName){
166
189
  return _config.plugins[pluginName];
167
190
  }
@@ -188,7 +188,7 @@ export class SpyneUtilsChannelRouteUrl {
188
188
  };
189
189
 
190
190
  const checkForEitherStrOrReMatch = either(
191
- propEq('str', mainStr), compose(test(__, mainStr), prop('re'))
191
+ propEq(mainStr, 'str'), compose(test(__, mainStr), prop('re'))
192
192
  );
193
193
 
194
194
  const findMatchIndex = compose(findLastIndex(equals(true)), map(checkForEitherStrOrReMatch), map(createStrRegexTest), map(checkForEmpty));
@@ -55,13 +55,12 @@ export class SpyneUtilsChannelRoute {
55
55
  return obj;
56
56
  };
57
57
 
58
- const createPred = p => compose(keys, filter(propEq(p, true)));
58
+ const createPred = p => compose(keys, filter(propEq(true, p)));
59
59
 
60
60
  const getPropsState = compose(map(compareProps), uniq, chain(keys))([obj1, obj2]);
61
61
  let pathsChanged = chain(createPred('changed'), getPropsState);
62
62
  let pathsAdded = chain(createPred('added'), getPropsState);
63
63
  let pathsRemoved = chain(createPred('removed'), getPropsState);
64
- // console.log("GET KEYS ", pathsChanged);
65
64
  obj1 = obj2;
66
65
  return { pathsAdded, pathsRemoved, pathsChanged };
67
66
  },