From 8e34c76fb797ec4bb94c84352d56e2fc6e0427b1 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 5 Mar 2018 00:39:13 +0300 Subject: [PATCH] some refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/core.js | 99 +++++++++++-- ui (gen4)/features/store.js | 4 +- ui (gen4)/features/ui-widgets.js | 27 ++-- ui (gen4)/package-lock.json | 231 +++++++++++++++++++++++++++++-- ui (gen4)/package.json | 5 +- 5 files changed, 328 insertions(+), 38 deletions(-) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 62395cf9..3cd491d6 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -104,8 +104,9 @@ var ImageGridMetaActions = module.ImageGridMetaActions = { // Test if the action is a Toggler... // - isToggler: actions.doWithRootAction(function(action){ - return action instanceof toggler.Toggler }), + isToggler: + actions.doWithRootAction(function(action){ + return action instanceof toggler.Toggler }), // Handle special cases where we need to get the action result early, // without calling handlers... @@ -300,11 +301,7 @@ var IntrospectionActions = actions.Actions({ d.slice() : this.actions.filter(this.isEvent.bind(this)) }) }, - isUserCallable: ['- System/', - doc`Test if an action is callable by user. - - .isUserCallable() - `, + isUserCallable: // XXX should this check only the root action or the whole set??? // ...in other words: can we make an action non-user-callable // anywhere other than the root action? @@ -312,10 +309,10 @@ var IntrospectionActions = actions.Actions({ //function(action){ // return this.getActionAttr(action, '__not_user_callable__') != true }], actions.doWithRootAction(function(action){ - return action.__not_user_callable__ != true })], - isEvent: ['- System/', + return action.__not_user_callable__ != true }), + isEvent: actions.doWithRootAction(function(action){ - return !!action.__event__ })], + return !!action.__event__ }), }) @@ -339,6 +336,19 @@ module.Introspection = ImageGridFeatures.Feature({ // XXX should his have state??? // ...if so, should this be a toggler??? var LifeCycleActions = actions.Actions({ + __stop_handler: null, + __ready: null, + __ready_announce_requested: null, + + // introspection... + isStarted: function(){ + return !!this.__stop_handler }, + isStopped: function(){ + return !this.__stop_handler }, + isReady: function(){ + return !!this.__ready }, + + start: ['- System/', doc`Start core action/event @@ -355,11 +365,17 @@ var LifeCycleActions = actions.Actions({ This will trigger .declareReady() if no action called .requestReadyAnnounce() + This will trigger .started() event when done. + NOTE: .runtime attribute will not be available on the .pre handler phase. NOTE: .requestReadyAnnounce() should be called exclusively on the .pre handler phase as this will check and trigger the .ready() event before the .post phase starts. + NOTE: handlers bound to this action/event will get called on the + start *event* thus handlers bound when the system is already + started will not get called until next start, to bind a handler + to the started *state* bind to 'started' / .started() `, function(){ var that = this @@ -440,7 +456,18 @@ var LifeCycleActions = actions.Actions({ this.declareReady() } } + + // trigger the started event... + this.started() }], + started: ['- System/System started event', + doc` + `, + Event(function(){ + // System started event... + // + // Not intended for direct use. + })], ready: ['- System/System ready event', doc`Ready core event @@ -546,6 +573,58 @@ var LifeCycleActions = actions.Actions({ delete this.__stop_handler this.logger && this.logger.emit('stop') + + // trigger the stopped event... + this.stopped() + }], + stopped: ['- System/System stopped event', + doc` + `, + Event(function(){ + // System stopped event... + // + // Not intended for direct use. + })], + + + // trigger core events... + // + // NOTE: we do not need to do .one(..) as it is implemented via .on(..) + // + // XXX EXPERIMENTAL... + // ...should this be an action??? + on: ['- System/', + function(evt, ...rest){ + var func = rest.slice().pop() + evt = typeof(evt) == typeof('') ? evt.split(/\s/g) : evt + + // we trigger the handler AFTER it is registered... + return function(){ + // started... + Math.max( + evt.indexOf('started'), + evt.indexOf('started.pre'), + evt.indexOf('started.post')) >= 0 + && this.isStarted() + && func.call(this) + + // ready... + // NOTE: we are ignoring the '.pre' events here as we are already + // in the specific state... + Math.max( + evt.indexOf('ready'), + evt.indexOf('ready.post')) >= 0 + && this.isReady() + && func.call(this) + + // started... + Math.max( + evt.indexOf('stopped'), + evt.indexOf('stopped.pre'), + evt.indexOf('stopped.post')) >= 0 + && this.isStopped() + && func.call(this) + } }], }) diff --git a/ui (gen4)/features/store.js b/ui (gen4)/features/store.js index 866b6326..0bc4572d 100755 --- a/ui (gen4)/features/store.js +++ b/ui (gen4)/features/store.js @@ -573,9 +573,7 @@ function makeStorageHandler(storage){ keys = a instanceof Array ? a : keys keys // add parsed candidates... - .concat(keys - .map(function(k){ return resolvePath(k) })) - .unique() + .map(function(k){ return resolvePath(k) }) // clear keys not in store... .filter(function(k){ return dict[k] in storage || k in storage }) diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 605fcf47..7bcb6ad6 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -658,33 +658,30 @@ var DialogsActions = actions.Actions({ // testers... // // ui elements... - isUIContainer: ['- Interface/', - function(action){ - return !!this.getActionAttr(action, '__container__') }], - isUIDialog: ['- Interface/', - function(action){ - return !!this.getActionAttr(action, '__dialog__') }], - isUIElement: ['- Interface/', - function(action){ - return this.isUIDialog(action) || this.isUIContainer(action) }], + isUIContainer: function(action){ + return !!this.getActionAttr(action, '__container__') }, + isUIDialog: function(action){ + return !!this.getActionAttr(action, '__dialog__') }, + isUIElement: function(action){ + return this.isUIDialog(action) || this.isUIContainer(action) }, // extended ui elements // ...first defined as a non-ui action and extended to a ui element. - isUIExtendedContainer: ['- Interface/', + isUIExtendedContainer: actions.doWithRootAction(function(action, name){ return action != null && !action.__container__ - && this.isUIContainer(name) })], - isUIExtendedDialog: ['- Interface/', + && this.isUIContainer(name) }), + isUIExtendedDialog: actions.doWithRootAction(function(action, name){ return action != null && !action.__dialog__ - && this.isUIDialog(name) })], - isUIExtendedElement: ['- Interface/', + && this.isUIDialog(name) }), + isUIExtendedElement: actions.doWithRootAction(function(action, name){ return action != null && !action.__dialog__ && !action.__container__ - && this.isUIElement(name) })], + && this.isUIElement(name) }), // container constructors... diff --git a/ui (gen4)/package-lock.json b/ui (gen4)/package-lock.json index ec556092..92d37dc9 100755 --- a/ui (gen4)/package-lock.json +++ b/ui (gen4)/package-lock.json @@ -4,6 +4,15 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "agent-base": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz", + "integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==", + "dev": true, + "requires": { + "es6-promisify": "5.0.0" + } + }, "ajv": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", @@ -48,6 +57,12 @@ "resolved": "https://registry.npmjs.org/async-json/-/async-json-0.0.2.tgz", "integrity": "sha1-qnEn2wOejkPaxyvR+7Z7oz9WgnA=" }, + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==", + "dev": true + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -193,12 +208,22 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, + "concat-stream": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", + "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", + "dev": true, + "requires": { + "inherits": "2.0.3", + "readable-stream": "2.3.5", + "typedarray": "0.0.6" + } + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true, - "optional": true + "dev": true }, "create-error-class": { "version": "3.0.2", @@ -314,6 +339,21 @@ "prr": "1.0.1" } }, + "es6-promise": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz", + "integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ==", + "dev": true + }, + "es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "dev": true, + "requires": { + "es6-promise": "4.2.4" + } + }, "exiftool": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/exiftool/-/exiftool-0.0.3.tgz", @@ -326,6 +366,44 @@ "dev": true, "optional": true }, + "extract-zip": { + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.6.tgz", + "integrity": "sha1-EpDt6NINCHK0Kf0/NRyhKOxe+Fw=", + "dev": true, + "requires": { + "concat-stream": "1.6.0", + "debug": "2.6.9", + "mkdirp": "0.5.0", + "yauzl": "2.4.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", + "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + } + } + }, "extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", @@ -353,6 +431,15 @@ } } }, + "fd-slicer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", + "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=", + "dev": true, + "requires": { + "pend": "1.2.0" + } + }, "flickrapi": { "version": "0.3.36", "resolved": "https://registry.npmjs.org/flickrapi/-/flickrapi-0.3.36.tgz", @@ -1067,15 +1154,25 @@ "sshpk": "1.13.1" } }, + "https-proxy-agent": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.0.tgz", + "integrity": "sha512-uUWcfXHvy/dwfM9bqa6AozvAjS32dZSTUYd/4SEpYKRg6LEcPLshksnQYRudM9AyNvUARMfAg5TLjUDyX/K4vA==", + "dev": true, + "requires": { + "agent-base": "4.2.0", + "debug": "3.1.0" + } + }, "iconv-lite": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, "ig-actions": { - "version": "3.18.0", - "resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.18.0.tgz", - "integrity": "sha512-wiN7pjt5CfklD/XNiehJnxrAn6/K7/dorUAYG0zTItYTCtp3iqyPCDtFiAF/PAFMbWjbiQxA2w8oIrZNV1QECQ==", + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.19.0.tgz", + "integrity": "sha512-8X5W7yNtsrwi35RnR+K5H6+/CtEb/dFVXrJEPxOxeByH3njuHwC44MMr3wLIXS0XVH1vM8xjlHsUd0uFU37J5A==", "requires": { "ig-object": "1.0.2" } @@ -1085,7 +1182,7 @@ "resolved": "https://registry.npmjs.org/ig-features/-/ig-features-3.3.4.tgz", "integrity": "sha512-nJmMDfY6JiyQ2mQj31oMOmw/HOY4zbN6yyPEFu61ySXU/f3+CC/GZjdaYFemVbnZThC7hcxYfmj62eSjt7oT+Q==", "requires": { - "ig-actions": "3.18.0", + "ig-actions": "3.19.0", "ig-object": "1.0.2" } }, @@ -1146,6 +1243,12 @@ "dev": true, "optional": true }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, "isomorphic-fetch": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", @@ -1334,8 +1437,7 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", - "dev": true, - "optional": true + "dev": true }, "mime-db": { "version": "1.30.0", @@ -1433,6 +1535,12 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, + "pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", + "dev": true + }, "performance-now": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", @@ -1462,6 +1570,18 @@ "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz", "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=" }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "dev": true + }, + "progress": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", + "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=", + "dev": true + }, "promise": { "version": "https://registry.npmjs.org/promise/-/promise-7.1.1.tgz", "integrity": "sha512-mxw1Fcl1jxLdpzS7MTIxrdiWk3CeMvZvVSGWE4P9eml3diZPBZTNV4oQsdYY3fY6j9udbmC1mSP6lqlzg6voBA==", @@ -1480,6 +1600,12 @@ "object-assign": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" } }, + "proxy-from-env": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.0.0.tgz", + "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=", + "dev": true + }, "prr": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", @@ -1494,6 +1620,33 @@ "dev": true, "optional": true }, + "puppeteer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.1.1.tgz", + "integrity": "sha1-rb8l5J9e8DRDwQq44JqVTKDHv+4=", + "dev": true, + "requires": { + "debug": "2.6.9", + "extract-zip": "1.6.6", + "https-proxy-agent": "2.2.0", + "mime": "1.6.0", + "progress": "2.0.0", + "proxy-from-env": "1.0.0", + "rimraf": "2.6.2", + "ws": "3.3.3" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, "qs": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", @@ -1537,6 +1690,21 @@ "prop-types": "15.6.0" } }, + "readable-stream": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.5.tgz", + "integrity": "sha512-tK0yDhrkygt/knjowCUiWP9YdV7c5R+8cR0r/kt9ZhBU906Fs6RpQJCEilamRJj1Nx2rWI6LkW9gKqjTkshhEw==", + "dev": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.1", + "string_decoder": "1.0.3", + "util-deprecate": "1.0.2" + } + }, "request": { "version": "2.81.0", "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", @@ -1686,6 +1854,15 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", @@ -1748,11 +1925,23 @@ "dev": true, "optional": true }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, "ua-parser-js": { "version": "0.7.14", "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.14.tgz", "integrity": "sha1-EQ1T+kw/MmwSEpK76skE0uAzh8o=" }, + "ultron": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", + "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==", + "dev": true + }, "universalify": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", @@ -1771,6 +1960,12 @@ "prepend-http": "1.0.4" } }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, "uuid": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", @@ -1929,6 +2124,26 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "ws": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", + "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", + "dev": true, + "requires": { + "async-limiter": "1.0.0", + "safe-buffer": "5.1.1", + "ultron": "1.1.1" + } + }, + "yauzl": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", + "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=", + "dev": true, + "requires": { + "fd-slicer": "1.0.1" + } } } } diff --git a/ui (gen4)/package.json b/ui (gen4)/package.json index a7f358fb..e339d79a 100755 --- a/ui (gen4)/package.json +++ b/ui (gen4)/package.json @@ -26,7 +26,7 @@ "fs-walk": "^0.0.1", "glob": "^4.0.6", "guarantee-events": "^1.0.0", - "ig-actions": "^3.18.0", + "ig-actions": "^3.19.0", "ig-features": "^3.3.4", "ig-object": "^1.0.2", "moment": "^2.21.0", @@ -46,7 +46,8 @@ }, "devDependencies": { "electron-wix-msi": "^1.3.0", - "less": "^3.0.1" + "less": "^3.0.1", + "puppeteer": "^1.1.1" }, "bin": { "ig": "ig.js"