mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
b126de5c2d
Avoids inconsistent state where the store might set `null` or `undefined` due to the server’s response
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
import { altWhitelabel } from '../alt';
|
|
import WhitelabelActions from '../actions/whitelabel_actions';
|
|
import WhitelabelSource from '../sources/whitelabel_source';
|
|
|
|
|
|
class WhitelabelStore {
|
|
constructor() {
|
|
this.whitelabel = {};
|
|
this.whitelabelMeta = {
|
|
invalidateCache: false,
|
|
err: null
|
|
};
|
|
|
|
this.bindActions(WhitelabelActions);
|
|
this.registerAsync(WhitelabelSource);
|
|
}
|
|
|
|
onFetchWhitelabel(invalidateCache) {
|
|
this.whitelabelMeta.invalidateCache = invalidateCache;
|
|
|
|
if(!this.getInstance().isLoading()) {
|
|
this.getInstance().lookupWhitelabel();
|
|
}
|
|
}
|
|
|
|
onSuccessFetchWhitelabel({ whitelabel = {} }) {
|
|
this.whitelabelMeta.invalidateCache = false;
|
|
this.whitelabelMeta.err = null;
|
|
this.whitelabel = whitelabel;
|
|
}
|
|
|
|
onErrorCurrentUser(err) {
|
|
console.logGlobal(err);
|
|
this.whitelabelMeta.err = err;
|
|
}
|
|
}
|
|
|
|
export default altWhitelabel.createStore(WhitelabelStore, 'WhitelabelStore');
|