store.subscribe(() => { let state: State = store.getState(); let app = document.getElementById("app"); let innerText = ''; state.forEach((elem => { innerText += ` <p>${elem}</p> `; })); app.innerHTML = innerText; });
response: () => { // This dispatch will trigger the listener, but it shouldn't trigger any // other requests. store.dispatch({ type: null }); let body = generateGetUIDataResponse({ [KEY_REGISTRATION_SYNCHRONIZED]: false, [KEY_HELPUS]: {optin: true}, }); return { body }; },
store.subscribe(() => { const state = store.getState(); for (const { key, selector, storage, save } of keeps) { const result = selector(state); if (result !== results[key]) { results[key] = result; save(key, result, storage); } } });
store.subscribe(throttle((): void => { const state = store.getState(); // The state is Immutable Map if (state.get("isLoading") === true || state.get("valid") === false) { return void 0; } const prevFmtString = (prevState.get("input") || "").split(" ")[0]; const currFmtString = (state.get("input") || "").split(" ")[0]; if ( typeof prevState.get === "function" && state.get("input").length > 0 && state.get("hexData").length > 0 && ( prevFmtString !== currFmtString || prevState.get("hexData") !== state.get("hexData") ) ) { store.dispatch(actions.startLoading()); const body: APIBody = { formatString: state.get("input"), input: state.get("hexData"), }; request.post(API_PATH, body) .then((res) => { let data = res.data; if (typeof data === "string") { data = JSON.parse(`${data}`); } store.dispatch(actions.updateResults(data.results)); store.dispatch(actions.stopLoading()); }) .catch((err: AxiosError) => { const errorMsg = (err.response ? err.response.data.error : err.message) || err.message || "Unknown Error"; store.dispatch(actions.stopLoading()); store.dispatch(actions.apiError(errorMsg)); }); } prevState = state; }, REQUEST_INTERVAL));
const configureStore = (initialState?: State) => { const finalCreateStore = compose(applyMiddleware(thunk))(createStore); const store: Store<State> = finalCreateStore(rootReducer, initialState); if (module.hot) { module.hot.accept('./rootReducer', () => { const nextRootReducer = require('./rootReducer').default; store.replaceReducer(nextRootReducer); }); } return store; };
it("should return false if no data is missing", function () { store.dispatch(clusterReducerObj.receiveData(new protos.cockroach.server.serverpb.ClusterResponse({cluster_id: CLUSTER_ID}))); store.dispatch(setUIDataKey(KEY_HELPUS, {})); store.dispatch(setUIDataKey(KEY_REGISTRATION_SYNCHRONIZED, true)); assert.isFalse(registrationService.shouldLoadKeys(store.getState())); assert.isFalse(registrationService.shouldLoadClusterInfo(store.getState())); assert.isFalse(registrationService.shouldLoadData(store.getState())); });
store.subscribe(() => { let state = store.getState(); clearTimeout(timeout); if (state.cachedData.cluster.data && state.cachedData.cluster.data.cluster_id && state.uiData[KEY_REGISTRATION_SYNCHRONIZED] && state.uiData[KEY_REGISTRATION_SYNCHRONIZED].data ) { assert.lengthOf(fetchMock.calls(uiDataFetchURL), 1); assert.lengthOf(fetchMock.calls(clusterFetchURL), 1); assert.lengthOf(fetchMock.calls(registrationFetchURLPrefix), 0); timeout = setTimeout(() => done()); } });
return (action: Action) => { let result = next(action); if (action.type !== TOGGLE_PLAYBACK) { return result; } if (store.getState().isPlaying) { start(); } else { stop(); } return result; };
pendingChannelIds.forEach(async channelId => { if (isLocked || !didInit) { return } const paymentChannel = await machinomy.channelById(channelId) if (paymentChannel) { // Initialize channel with a 0 tip await this.initChannel() // Remove channelId from watchers this.store.dispatch(actions.removePendingChannel(channelId)) } })
beforeEach(() => { store = applyMiddleware(ThunkMiddleware)(createStore)(reducer); dataLoaderSpy = sinon.spy(); store.dispatch({ type: ActionType.SET_DATA_LOADER, payload: dataLoaderSpy }); store.dispatch({ type: ActionType.SET_SERIES_IDS, payload: ALL_SERIES }); store.dispatch({ type: ActionType.DATA_RETURNED, payload: { [SERIES_A]: [], [SERIES_B]: [] } }); });