From 30acf183362020b2c1e97646f21ff96853af1a5a Mon Sep 17 00:00:00 2001 From: Elliott Marquez Date: Thu, 13 Apr 2017 13:07:42 -0700 Subject: [PATCH 1/3] buildable in closure save -> saveValue API change --- .../app-indexeddb-mirror-client.html | 8 +++--- .../app-indexeddb-mirror-worker.js | 20 +++++++------- .../app-indexeddb-mirror.html | 9 ++----- app-indexeddb-mirror/common-worker-scope.js | 2 +- app-indexeddb-mirror/common-worker.html | 13 +++++---- .../app-localstorage-document.html | 27 +++++-------------- app-storage-behavior.html | 12 ++++----- 7 files changed, 40 insertions(+), 51 deletions(-) diff --git a/app-indexeddb-mirror/app-indexeddb-mirror-client.html b/app-indexeddb-mirror/app-indexeddb-mirror-client.html index 5f6d8e7..585196f 100644 --- a/app-indexeddb-mirror/app-indexeddb-mirror-client.html +++ b/app-indexeddb-mirror/app-indexeddb-mirror-client.html @@ -27,6 +27,8 @@ * * @param {string} _workerUrl The URL to use when initializing the * corresponding WebWorker. + * + * @constructor */ Polymer.AppIndexedDBMirrorClient = function AppIndexedDBMirrorClient(_workerUrl) { @@ -53,7 +55,7 @@ * * @param {string} session The session to validate the current session * against. - * @return {Promise} A promise that resolves when the worker confirms that + * @return {Promise|undefined} A promise that resolves when the worker confirms that * the session has been validated. */ validateSession: function(session) { @@ -73,7 +75,7 @@ * Sends a message to the worker and awaits and handles a corresponding * response. * - * @param {} message Any value that can be sent via `postMessage` to the + * @param {*} message Any value that can be sent via `postMessage` to the * worker. * @return {Promise} A promise that resolves when a corresponding response * message has been received by from the worker. Requests are given a @@ -113,7 +115,7 @@ * `"set"`) * @param {string} key The key in the IndexedDB object store to operate * on. - * @param {=} value The value to set at `key`, if using the `"set"` + * @param {Object} value The value to set at `key`, if using the `"set"` * `method`. * @return {Promise} A promise that resolves when the worker indicates * that the transaction has completed. diff --git a/app-indexeddb-mirror/app-indexeddb-mirror-worker.js b/app-indexeddb-mirror/app-indexeddb-mirror-worker.js index 0d91190..7a5ce2c 100644 --- a/app-indexeddb-mirror/app-indexeddb-mirror-worker.js +++ b/app-indexeddb-mirror/app-indexeddb-mirror-worker.js @@ -38,6 +38,8 @@ * open. * @param {string} _storeName The name of the IndexedDB object store to use * for storing values. + * + * @constructor */ function AppIndexedDBMirrorWorker(_dbName, _storeName) { _dbName = _dbName || 'app-mirror'; @@ -112,14 +114,14 @@ * store instance. * @param {string} storeName The name of the object store to operate on. * @param {string} mode The mode of the transaction that will be performed. - * @param {...} operationArg The arguments to call the method named by + * @param {...*} operationArgs The arguments to call the method named by * the operation parameter. * @return {Promise} A promise that resolves when the transaction completes, * with the result of the transaction, or rejects if the transaction fails * with the error reported by the transaction. */ - operateOnStore: function(operation, storeName, mode) { - var operationArgs = Array.from(arguments).slice(3); + operateOnStore: function(operation, storeName, mode, operationArgs) { + operationArgs = Array.from(arguments).slice(3); return this.openDb().then(function(db) { @@ -159,7 +161,7 @@ * @param {string} storeName The name of the object store to operate on. * @param {string} key The key in the object store that corresponds to the * value that should be put. - * @param {} value The value to be put in the object store at the given key. + * @param {*} value The value to be put in the object store at the given key. * @return {Promise} A promise that resolves with the outcome of the * operation. */ @@ -184,7 +186,7 @@ * @param {string} method The method of the transaction. Supported methods * are `"get"` and `"set"`. * @param {string} key The key to get or set. - * @param {=} value The value to set, when the method is `"set"`. + * @param {Object} value The value to set, when the method is `"set"`. * @return {Promise} A promise that resolves with the outcome of the * transaction, or rejects if an unsupported method is attempted. */ @@ -240,8 +242,8 @@ port.addEventListener('message', function(event) { this.handleClientMessage(event, port) }.bind(this)); - - if (!(port in this[CLIENT_PORTS])) { + let isPortInClient = port.toString() in this[CLIENT_PORTS]; + if (!isPortInClient) { this[CLIENT_PORTS].push(port); } @@ -265,7 +267,7 @@ */ handleClientMessage: function(event, port) { if (!event.data) { - return; + return null; } var id = event.data.id; @@ -307,7 +309,7 @@ } }; - self.appIndexedDBMirrorWorker = new AppIndexedDBMirrorWorker(); + self.appIndexedDBMirrorWorker = new AppIndexedDBMirrorWorker('', ''); self.addEventListener('connect', function(event) { self.appIndexedDBMirrorWorker.registerClient(event.ports[0]) diff --git a/app-indexeddb-mirror/app-indexeddb-mirror.html b/app-indexeddb-mirror/app-indexeddb-mirror.html index 407ab69..9f871f9 100644 --- a/app-indexeddb-mirror/app-indexeddb-mirror.html +++ b/app-indexeddb-mirror/app-indexeddb-mirror.html @@ -181,7 +181,7 @@ * Worker spawned from `workerUrl`. */ client: { - type: Polymer.AppIndexedDBMirrorClient, + type: Object, computed: '__computeClient(workerUrl)', observer: '__clientChanged' }, @@ -204,17 +204,14 @@ '__updatePersistedData(data.*)', ], - /** @override */ get isNew() { return false; }, - /** @override */ destroy: function() { return this.client.transaction('set', this.key, null); }, - /** @override */ setStoredValue: function(path, value) { if (this.online) { return this.client.transaction('set', this.key, this.data); @@ -223,12 +220,10 @@ return Promise.resolve(); }, - /** @override */ getStoredValue: function(path) { return this.client.transaction('get', this.key); }, - /** @override */ initializeStoredValue: function() { return Promise.resolve(); }, @@ -253,7 +248,7 @@ this.persistedData = this.data; this.linkPaths('data', 'persistedData'); } else { - this.unlinkPaths('data', 'persistedData'); + this.unlinkPaths('data'); this._enqueueTransaction(function() { return this.getStoredValue().then(function(value) { // We may have gone online since retrieving the persisted value.. diff --git a/app-indexeddb-mirror/common-worker-scope.js b/app-indexeddb-mirror/common-worker-scope.js index 15832d8..7ea8aed 100644 --- a/app-indexeddb-mirror/common-worker-scope.js +++ b/app-indexeddb-mirror/common-worker-scope.js @@ -49,5 +49,5 @@ } }.bind(this)); - self.importScripts([workerScript]); + self.importScripts(workerScript); })(); diff --git a/app-indexeddb-mirror/common-worker.html b/app-indexeddb-mirror/common-worker.html index 8b5b148..ee38725 100644 --- a/app-indexeddb-mirror/common-worker.html +++ b/app-indexeddb-mirror/common-worker.html @@ -40,6 +40,8 @@ * * @param {string} workerUrl The URL of the worker script to create a worker * instance with. + * + * @constructor */ Polymer.CommonWorker = function CommonWorker (workerUrl) { if (HAS_SHARED_WORKER) { @@ -82,10 +84,11 @@ * A proxy method that forwards all calls to the backing `WebWorker` * instance. * - * @param {...} addEventListenerArgs The arguments to call the same method - * on the `WebWorker` with. + * @param {String|string|undefined} eventType The event to listen for + * @param {Function} listenerFunction The function to be attached to the event + * @param {Object=} options addEventListener Options object */ - addEventListener: function() { + addEventListener: function(eventType, listenerFunction, options) { if (this.webWorker) { return this.webWorker.addEventListener.apply(this.webWorker, arguments); } @@ -95,10 +98,10 @@ * A proxy method that forwards all calls to the backing `WebWorker` * instance. * - * @param {...} removeEventListenerArgs The arguments to call the same + * @param {Array} removeEventListenerArgs The arguments to call the same * method on the `WebWorker` with. */ - removeEventListener: function() { + removeEventListener: function(removeEventListenerArgs) { if (this.webWorker) { return this.webWorker .removeEventListener.apply(this.webWorker, arguments); diff --git a/app-localstorage/app-localstorage-document.html b/app-localstorage/app-localstorage-document.html index 792b2f4..623b5d5 100644 --- a/app-localstorage/app-localstorage-document.html +++ b/app-localstorage/app-localstorage-document.html @@ -47,6 +47,8 @@ properties: { /** * Defines the logical location to store the data. + * + * @type{String} */ key: { type: String, @@ -93,9 +95,6 @@ '__onAppLocalStorageChanged'); }, - /** - * @override - */ get isNew() { return !this.key; }, @@ -103,32 +102,26 @@ /** * Stores a value at the given key, and if successful, updates this.key. * - * @override - * @param {string} key The new key to use. + * @param {*} key The new key to use. + * @return {Promise} */ - save: function(key) { + saveValue: function(key) { try { - this.__setStorageValue(key, this.data); + this.__setStorageValue(/*{@type if (key ty){String}}*/key, this.data); } catch(e) { return Promise.reject(e); } - this.key = key; + this.key = /** @type {String} */ (key); return Promise.resolve(); }, - /** - * @override - */ reset: function() { this.key = null; this.data = this.zeroValue; }, - /** - * @override - */ destroy: function() { try { this.storage.removeItem(this.key); @@ -140,9 +133,6 @@ return Promise.resolve(); }, - /** - * @override - */ getStoredValue: function(path) { var value; @@ -165,9 +155,6 @@ return Promise.resolve(value); }, - /** - * @override - */ setStoredValue: function(path, value) { if (this.key != null) { try { diff --git a/app-storage-behavior.html b/app-storage-behavior.html index e91563b..7f8855e 100644 --- a/app-storage-behavior.html +++ b/app-storage-behavior.html @@ -8,7 +8,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> -