aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/config-manager.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-04-16 04:04:17 +0800
committerkumavis <aaron@kumavis.me>2016-04-16 04:04:17 +0800
commitd6114292d0c05b42b1d28d75baad8af0c06509a1 (patch)
treea93d1f15590ddfce886392bca175803184bb66c4 /app/scripts/lib/config-manager.js
parentd840e81a101351bd661668cf0b1f9e5b73683890 (diff)
downloadtangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.gz
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.bz2
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.lz
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.xz
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.tar.zst
tangerine-wallet-browser-d6114292d0c05b42b1d28d75baad8af0c06509a1.zip
inpage - use publicConfigStore for selectedAccount and sync provider
Diffstat (limited to 'app/scripts/lib/config-manager.js')
-rw-r--r--app/scripts/lib/config-manager.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index c557891fe..f024729cc 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -15,6 +15,8 @@ const migrations = require('./migrations')
*/
module.exports = ConfigManager
function ConfigManager() {
+ // ConfigManager is observable and will emit updates
+ this._subs = []
/* The migrator exported on the config-manager
* has two methods the user should be concerned with:
@@ -47,6 +49,7 @@ ConfigManager.prototype.setConfig = function(config) {
var data = this.migrator.getData()
data.config = config
this.setData(data)
+ this._emitUpdates(config)
}
ConfigManager.prototype.getConfig = function() {
@@ -127,6 +130,30 @@ ConfigManager.prototype.clearWallet = function() {
this.setData(data)
}
+ConfigManager.prototype.setData = function(data) {
+ this.migrator.saveData(data)
+}
+
+// observable
+
+ConfigManager.prototype.subscribe = function(fn){
+ this._subs.push(fn)
+ var unsubscribe = this.unsubscribe.bind(this, fn)
+ return unsubscribe
+}
+
+ConfigManager.prototype.unsubscribe = function(fn){
+ var index = this._subs.indexOf(fn)
+ if (index !== -1) this._subs.splice(index, 1)
+}
+
+ConfigManager.prototype._emitUpdates = function(state){
+ this._subs.forEach(function(handler){
+ handler(state)
+ })
+}
+
+
function loadData() {
var oldData = getOldStyleData()