From 6dbdc87713a652dec4c90fa792dda08d613d4198 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Wed, 18 Apr 2018 17:24:36 -0400 Subject: Add generated docs --- docs/jsdocs/lib_ComposableObservableStore.js.html | 118 ++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 docs/jsdocs/lib_ComposableObservableStore.js.html (limited to 'docs/jsdocs/lib_ComposableObservableStore.js.html') diff --git a/docs/jsdocs/lib_ComposableObservableStore.js.html b/docs/jsdocs/lib_ComposableObservableStore.js.html new file mode 100644 index 000000000..dc39a9f55 --- /dev/null +++ b/docs/jsdocs/lib_ComposableObservableStore.js.html @@ -0,0 +1,118 @@ + + + + + + + lib/ComposableObservableStore.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

lib/ComposableObservableStore.js

+ + + + + + + +
+
+
const ObservableStore = require('obs-store')
+
+/**
+ * An ObservableStore that can composes a flat
+ * structure of child stores based on configuration
+ */
+class ComposableObservableStore extends ObservableStore {
+  /**
+   * Create a new store
+   *
+   * @param {Object} [initState] - The initial store state
+   * @param {Object} [config] - Map of internal state keys to child stores
+   */
+  constructor (initState, config) {
+    super(initState)
+    this.updateStructure(config)
+  }
+
+  /**
+   * Composes a new internal store subscription structure
+   *
+   * @param {Object} [config] - Map of internal state keys to child stores
+   */
+  updateStructure (config) {
+    this.config = config
+    this.removeAllListeners()
+    for (const key in config) {
+      config[key].subscribe((state) => {
+        this.updateState({ [key]: state })
+      })
+    }
+  }
+
+  /**
+   * Merges all child store state into a single object rather than
+   * returning an object keyed by child store class name
+   *
+   * @returns {Object} - Object containing merged child store state
+   */
+  getFlatState () {
+    let flatState = {}
+    for (const key in this.config) {
+      flatState = { ...flatState, ...this.config[key].getState() }
+    }
+    return flatState
+  }
+}
+
+module.exports = ComposableObservableStore
+
+
+
+ + + + +
+ +
+ + + + + + + + -- cgit v1.2.3