Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: third_party/polymer/components-chromium/core-localstorage/core-localstorage-extracted.js

Issue 592593002: Inline scripts were extracted from Polymer elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/echo ""/echo/ Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/components-chromium/core-localstorage/core-localstorage-extracted.js
diff --git a/third_party/polymer/components-chromium/core-localstorage/core-localstorage-extracted.js b/third_party/polymer/components-chromium/core-localstorage/core-localstorage-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..38f0ac939350bbf56ed7c8dc63f7df550a2cdd01
--- /dev/null
+++ b/third_party/polymer/components-chromium/core-localstorage/core-localstorage-extracted.js
@@ -0,0 +1,97 @@
+
+
+ Polymer('core-localstorage', {
+
+ /**
+ * Fired when a value is loaded from localStorage.
+ * @event core-localstorage-load
+ */
+
+ /**
+ * The key to the data stored in localStorage.
+ *
+ * @attribute name
+ * @type string
+ * @default null
+ */
+ name: '',
+
+ /**
+ * The data associated with the specified name.
+ *
+ * @attribute value
+ * @type object
+ * @default null
+ */
+ value: null,
+
+ /**
+ * If true, the value is stored and retrieved without JSON processing.
+ *
+ * @attribute useRaw
+ * @type boolean
+ * @default false
+ */
+ useRaw: false,
+
+ /**
+ * If true, auto save is disabled.
+ *
+ * @attribute autoSaveDisabled
+ * @type boolean
+ * @default false
+ */
+ autoSaveDisabled: false,
+
+ attached: function() {
+ // wait for bindings are all setup
+ this.async('load');
+ },
+
+ valueChanged: function() {
+ if (this.loaded && !this.autoSaveDisabled) {
+ this.save();
+ }
+ },
+
+ load: function() {
+ var v = localStorage.getItem(this.name);
+ if (this.useRaw) {
+ this.value = v;
+ } else {
+ // localStorage has a flaw that makes it difficult to determine
+ // if a key actually exists or not (getItem returns null if the
+ // key doesn't exist, which is not distinguishable from a stored
+ // null value)
+ // however, if not `useRaw`, an (unparsed) null value unambiguously
+ // signals that there is no value in storage (a stored null value would
+ // be escaped, i.e. "null")
+ // in this case we save any non-null current (default) value
+ if (v === null) {
+ if (this.value !== null) {
+ this.save();
+ }
+ } else {
+ try {
+ v = JSON.parse(v);
+ } catch(x) {
+ }
+ this.value = v;
+ }
+ }
+ this.loaded = true;
+ this.asyncFire('core-localstorage-load');
+ },
+
+ /**
+ * Saves the value to localStorage.
+ *
+ * @method save
+ */
+ save: function() {
+ var v = this.useRaw ? this.value : JSON.stringify(this.value);
+ localStorage.setItem(this.name, v);
+ }
+
+ });
+

Powered by Google App Engine
This is Rietveld 408576698