Skip to content

Commit

Permalink
Merge pull request #103 from PolymerElements/closure-buildable
Browse files Browse the repository at this point in the history
buildable in closure save -> saveValue API change
  • Loading branch information
e111077 authored Apr 13, 2017
2 parents a81299b + 79d0f34 commit 67bf12b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 50 deletions.
8 changes: 5 additions & 3 deletions app-indexeddb-mirror/app-indexeddb-mirror-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*
* @param {string} _workerUrl The URL to use when initializing the
* corresponding WebWorker.
*
* @constructor
*/
Polymer.AppIndexedDBMirrorClient =
function AppIndexedDBMirrorClient(_workerUrl) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 12 additions & 10 deletions app-indexeddb-mirror/app-indexeddb-mirror-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
* Class that implements a worker process negotiates connections from clients
* in other threads, and operates on an IndexedDB database object store.
*
* @param {string} _dbName The name of the IndexedDB database to create and
* @param {string=} _dbName The name of the IndexedDB database to create and
* open.
* @param {string} _storeName The name of the IndexedDB object store to use
* @param {string=} _storeName The name of the IndexedDB object store to use
* for storing values.
*
* @constructor
*/
function AppIndexedDBMirrorWorker(_dbName, _storeName) {
_dbName = _dbName || 'app-mirror';
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand Down Expand Up @@ -240,8 +242,8 @@
port.addEventListener('message', function(event) {
this.handleClientMessage(event, port)
}.bind(this));

if (!(port in this[CLIENT_PORTS])) {
var isPortInClient = port.toString() in this[CLIENT_PORTS];
if (!isPortInClient) {
this[CLIENT_PORTS].push(port);
}

Expand All @@ -265,7 +267,7 @@
*/
handleClientMessage: function(event, port) {
if (!event.data) {
return;
return null;
}

var id = event.data.id;
Expand Down
9 changes: 2 additions & 7 deletions app-indexeddb-mirror/app-indexeddb-mirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
* Worker spawned from `workerUrl`.
*/
client: {
type: Polymer.AppIndexedDBMirrorClient,
type: Object,
computed: '__computeClient(workerUrl)',
observer: '__clientChanged'
},
Expand All @@ -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);
Expand All @@ -223,12 +220,10 @@
return Promise.resolve();
},

/** @override */
getStoredValue: function(path) {
return this.client.transaction('get', this.key);
},

/** @override */
initializeStoredValue: function() {
return Promise.resolve();
},
Expand All @@ -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..
Expand Down
2 changes: 1 addition & 1 deletion app-indexeddb-mirror/common-worker-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
}
}.bind(this));

self.importScripts([workerScript]);
self.importScripts(workerScript);
})();
9 changes: 6 additions & 3 deletions app-indexeddb-mirror/common-worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
27 changes: 7 additions & 20 deletions app-localstorage/app-localstorage-document.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
properties: {
/**
* Defines the logical location to store the data.
*
* @type{String}
*/
key: {
type: String,
Expand Down Expand Up @@ -93,42 +95,33 @@
'__onAppLocalStorageChanged');
},

/**
* @override
*/
get isNew() {
return !this.key;
},

/**
* 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);
Expand All @@ -140,9 +133,6 @@
return Promise.resolve();
},

/**
* @override
*/
getStoredValue: function(path) {
var value;

Expand All @@ -165,9 +155,6 @@
return Promise.resolve(value);
},

/**
* @override
*/
setStoredValue: function(path, value) {
if (this.key != null) {
try {
Expand Down
12 changes: 6 additions & 6 deletions app-storage-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../promise-polyfill/promise-polyfill.html">
<script>
(function() {
'use strict';
Expand Down Expand Up @@ -123,10 +122,11 @@
* If the data value represented by this storage instance is new, this
* method generates an attempt to write the value to storage.
*
* @abstract
*
* @param {*} args
* @return {Promise} a Promise that settles only once the write has.
*/
save: function() {
saveValue: function(args) {
return Promise.resolve();
},

Expand All @@ -147,7 +147,7 @@
*/
destroy: function() {
this.data = this.zeroValue;
return this.save();
return this.saveValue();
},

/**
Expand Down Expand Up @@ -184,7 +184,7 @@
/**
* Override this method to implement reading a value from storage.
*
* @abstract
*
* @param {string} storagePath The path (through storage) of the value to
* create, relative to the root of storage associated with this instance.
* @return {Promise} A promise that resolves with the canonical value stored
Expand All @@ -201,7 +201,7 @@
* Override this method to implement creating and updating
* stored values.
*
* @abstract
*
* @param {string} storagePath The path of the value to update, relative
* to the root storage path configured for this instance.
* @param {*} value The updated in-memory value to apply to the stored value
Expand Down

0 comments on commit 67bf12b

Please sign in to comment.