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

Unified Diff: chrome/browser/resources/md_bookmarks/bookmarks_store.js

Issue 2731473002: MD Bookmarks: Implement basis for new data-binding system (Closed)
Patch Set: calamity@ review Created 3 years, 10 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
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/resources/md_bookmarks/compiled_resources2.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_bookmarks/bookmarks_store.js
diff --git a/chrome/browser/resources/md_bookmarks/bookmarks_store.js b/chrome/browser/resources/md_bookmarks/bookmarks_store.js
new file mode 100644
index 0000000000000000000000000000000000000000..59babbd67fc640c3b797e2565c65b663eec529ee
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/bookmarks_store.js
@@ -0,0 +1,82 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview A singleton datastore for the Bookmarks page. Page state is
+ * publicly readable, but can only be modified by dispatching an Action to
+ * the store.
+ */
+
+cr.define('bookmarks', function() {
+ /** @constructor */
+ function Store() {
+ /** @type {!BookmarksPageState} */
+ this.data_ = {};
+ /** @type {boolean} */
+ this.initialized_ = false;
+ /** @type {!Array<!StoreObserver>} */
+ this.observers_ = [];
+ }
+
+ Store.prototype = {
+ /**
+ * @param {!BookmarksPageState} initialState
+ */
+ init: function(initialState) {
+ this.data_ = initialState;
+ this.initialized_ = true;
+ this.notifyObservers_(this.data_);
+ },
+
+ /** @type {!BookmarksPageState} */
+ get data() {
+ return this.data_;
+ },
+
+ /** @return {boolean} */
+ isInitialized: function() {
+ return this.initialized_;
+ },
+
+ /** @param {!StoreObserver} observer */
+ addObserver: function(observer) {
+ this.observers_.push(observer);
+ },
+
+ /** @param {!StoreObserver} observer */
+ removeObserver: function(observer) {
+ var index = this.observers_.indexOf(observer);
+ this.observers_.splice(index, 1);
+ },
+
+ /**
+ * Transition to a new UI state based on the supplied |action|, and notify
+ * observers of the change.
+ * @param {Action} action
+ */
+ handleAction: function(action) {
+ if (!this.initialized_)
+ return;
+
+ this.data_ = bookmarks.reduceAction(this.data_, action);
+ this.notifyObservers_(this.data_);
+ },
+
+ /**
+ * @param {!BookmarksPageState} state
+ * @private
+ */
+ notifyObservers_: function(state) {
+ this.observers_.forEach(function(o) {
+ o.onStateChanged(state);
+ });
+ },
+ };
+
+ cr.addSingletonGetter(Store);
+
+ return {
+ Store: Store,
+ };
+});
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/resources/md_bookmarks/compiled_resources2.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698