Sha256: 81a954799a84b75d2a59e66ea799df6b88ade7c1beccdca3919c589ffc14da77
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
import {createStore} from 'fluxxor'; import {SEARCH as constants} from '../constants'; var fieldMapping = { SEARCH_RESULT: 'results' }; export default createStore({ initialize() { this.data = this._fresh(); this.bindActions( constants.LOAD, this.onLoad, constants.LOAD_SUCCESS, this.onLoadSuccess, constants.LOAD_FAIL, this.onLoadFail ); }, _fresh() { return { results: [], loading: { results: true } }; }, onLoad(payload) { if (typeof payload.type === 'undefined') { this.data = this._fresh(); this.data.identifier = payload.id; this.emit('change'); } else if (payload.id === this.data.identifier) { this.turn(payload.type, true); this.emit('change'); } }, onLoadSuccess(payload) { if (payload.id === this.data.identifier) { this.turn(payload.type, false); this.setData(payload); this.emit('change'); } }, onLoadFail(payload) { this.turn(payload.type, false); }, turn(type, state) { var fields = fieldMapping[type]; if (typeof fields === 'object') { fields.forEach((field) => { this.data.loading[field] = state; }); } else { this.data.loading[fields] = state; } }, setData(payload) { switch (payload.type) { case 'SEARCH_RESULT': this.data.results = payload.res.body; break; default: } }, getData() { return this.data; } });
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
conjur-asset-ui-1.6.0 | app/src/stores/search_store.js |