本文整理匯總了TypeScript中redux.Store類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Store類的具體用法?TypeScript Store怎麽用?TypeScript Store使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Store類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: compose
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;
};
示例2: beforeEach
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]: []
}
});
});
示例3:
store.subscribe(() => {
let state: State = store.getState();
let app = document.getElementById("app");
let innerText = '';
state.forEach((elem => {
innerText += `
<p>${elem}</p>
`;
}));
app.innerHTML = innerText;
});
示例4: generateGetUIDataResponse
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 };
},
示例5: selector
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);
}
}
});
示例6:
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));
示例7: it
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()));
});
示例8: clearTimeout
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());
}
});
示例9: return
return (action: Action) => {
let result = next(action);
if (action.type !== TOGGLE_PLAYBACK) {
return result;
}
if (store.getState().isPlaying) {
start();
} else {
stop();
}
return result;
};
示例10:
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))
}
})