summaryrefslogtreecommitdiffstats
path: root/web/react/stores
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-12-15 11:36:14 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-12-15 11:36:14 -0500
commite4899fa551d53ec07718659eed97178052982552 (patch)
treecb3169be1035ac5c17a3dffa24f86a90f5850fa4 /web/react/stores
parent2980a56370dfe150952beeb97c25e5e21e7fc7e5 (diff)
downloadchat-e4899fa551d53ec07718659eed97178052982552.tar.gz
chat-e4899fa551d53ec07718659eed97178052982552.tar.bz2
chat-e4899fa551d53ec07718659eed97178052982552.zip
Improved PreferenceStore api when getting values
Diffstat (limited to 'web/react/stores')
-rw-r--r--web/react/stores/preference_store.jsx49
1 files changed, 46 insertions, 3 deletions
diff --git a/web/react/stores/preference_store.jsx b/web/react/stores/preference_store.jsx
index 543129aca..79eab4fe1 100644
--- a/web/react/stores/preference_store.jsx
+++ b/web/react/stores/preference_store.jsx
@@ -23,8 +23,11 @@ class PreferenceStoreClass extends EventEmitter {
super();
this.getAllPreferences = this.getAllPreferences.bind(this);
+ this.get = this.get.bind(this);
+ this.getBool = this.getBool.bind(this);
+ this.getInt = this.getInt.bind(this);
this.getPreference = this.getPreference.bind(this);
- this.getPreferences = this.getPreferences.bind(this);
+ this.getCategory = this.getCategory.bind(this);
this.getPreferencesWhere = this.getPreferencesWhere.bind(this);
this.setAllPreferences = this.setAllPreferences.bind(this);
this.setPreference = this.setPreference.bind(this);
@@ -41,11 +44,51 @@ class PreferenceStoreClass extends EventEmitter {
return new Map(BrowserStore.getItem('preferences', []));
}
- getPreference(category, name, defaultValue = '') {
+ get(category, name, defaultValue = '') {
+ const preference = this.getAllPreferences().get(getPreferenceKey(category, name));
+
+ if (!preference) {
+ return defaultValue;
+ }
+
+ return preference.value || defaultValue;
+ }
+
+ getBool(category, name, defaultValue = false) {
+ const preference = this.getAllPreferences().get(getPreferenceKey(category, name));
+
+ if (!preference) {
+ return defaultValue;
+ }
+
+ // prevent a non-false default value from being returned instead of an actual false value
+ if (preference.value === 'false') {
+ return false;
+ }
+
+ return (preference.value !== 'false') || defaultValue;
+ }
+
+ getInt(category, name, defaultValue = 0) {
+ const preference = this.getAllPreferences().get(getPreferenceKey(category, name));
+
+ if (!preference) {
+ return defaultValue;
+ }
+
+ // prevent a non-zero default value from being returned instead of an actual 0 value
+ if (preference.value === '0') {
+ return 0;
+ }
+
+ return parseInt(preference.value, 10) || defaultValue;
+ }
+
+ getPreference(category, name, defaultValue = {}) {
return this.getAllPreferences().get(getPreferenceKey(category, name)) || defaultValue;
}
- getPreferences(category) {
+ getCategory(category) {
return this.getPreferencesWhere((preference) => (preference.category === category));
}