本文整理汇总了TypeScript中redux.createStore函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createStore函数的具体用法?TypeScript createStore怎么用?TypeScript createStore使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createStore函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: prod
function prod() {
return createStore(rootReducer as any, ({} as any), getMiddleware("production"));
}
示例2: next
return title;
}
});
const dumbMiddleware: Middleware = store => next => action => next(action);
const composedMiddleware = applyMiddleware(middleware, dumbMiddleware);
const storeEnhancer = compose<StoreCreator, StoreCreator, StoreCreator>(
enhancer,
composedMiddleware
);
const combined = combineReducers<State>({ location: reducer });
const store = createStore(combined, storeEnhancer);
// Test that `thunk()` has correct state types now that `store` is defined
thunk(store)
.then((t) => {
t = t!; // $ExpectType RouteThunk<State>
});
const receivedAction: ReceivedAction = {
type: 'HOME',
payload: {}
};
actionToPath(receivedAction, routesMap); // $ExpectType string
const querySerializer: QuerySerializer = {
stringify: (params) => '',
示例3: return
}
const rootReducer: Reducer<State> = () => ({});
const asyncNotify: BatchFunction = (() => {
let notifying = false;
return (notify: NotifyFunction) => {
if (notifying) {
return;
}
notifying = true;
setTimeout(() => {
notify();
notifying = false;
});
};
})();
const store = createStore(
rootReducer,
batchedSubscribe(asyncNotify)
);
const unsubscribe = store.subscribeImmediate(() => {
store.getState();
});
unsubscribe();
示例4: createStore
// TodoStore (store.ts)
import {combineReducers, createStore, Store} from 'redux';
import {todos} from './reducers/todos';
// Create the store using the todos reducer
export const TodoStore: Store = createStore(todos);
// Publish action to add a new Todo
export const addTodo: Function = (title: String) : void => {
// Dispatch will publish an action of type 'ADD_TODO', which
// runs through the reducer and gets caught in the
// case 'ADD_TODO': block
TodoStore.dispatch({
type: 'ADD_TODO',
title
})
}
// Publish action to toggle a Todo
export const toggleTodo: Function = (index: Number) : void => {
TodoStore.dispatch({
type: 'TOGGLE_TODO',
index
})
}
示例5: combineReducers
routerMiddleware,
push,
replace,
go,
goForward,
goBack,
routerActions
} from 'react-router-redux';
const reducer = combineReducers({ routing: routerReducer });
// Apply the middleware to the store
const browserHistory = createHistory()
const middleware = routerMiddleware(browserHistory);
const store = createStore(
reducer,
applyMiddleware(middleware)
);
// Create an enhanced history that syncs navigation events with the store
const history = syncHistoryWithStore(browserHistory, store);
history.listen(location => console.log(location) );
history.unsubscribe();
// Dispatch from anywhere like normal.
store.dispatch(push('/foo'));
store.dispatch(replace('/foo'));
store.dispatch(go(1));
store.dispatch(goForward());
store.dispatch(goBack());
store.dispatch(routerActions.push('/foo'));
store.dispatch(routerActions.replace('/foo'));
示例6: createStore
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { routing, appRoutingProviders } from 'src/app/app.routes';
import { AppComponent } from './app/app.component';
import { HomeComponent } from './app/views/home.component';
import { CreatePlayersComponent } from './app/views/create-players.component';
import { StartGameComponent } from './app/views/start-game.component';
import { PlayersPresentationComponent } from './app/views/players-presentation.component';
import {createStore} from 'redux';
import { killersReducer } from 'src/app/reducers/killersReducer';
const appStore = createStore(killersReducer);
import {
AddKillerFormComponent ,
DisplayPlayerComponent,
KillerComponent,
KillersBoardComponent,
KillersListComponent,
KillersListGameComponent,
UserAvatarComponent
} from 'src/app/components';
@NgModule({
imports: [
BrowserModule,
FormsModule,
routing
],
示例7: createStore
import { reducers } from '../reducers';
import { createStore, compose, applyMiddleware } from 'redux';
import reduxThunk from 'redux-thunk';
export const store = createStore(
reducers,
compose(
applyMiddleware(reduxThunk),
/* tslint:disable-next-line */
window["devToolsExtension"] ? window["devToolsExtension"]() : (f) => f,
),
);
示例8: configureStore
export function configureStore() {
return createStore(rootReducer, defaultState, applyMiddleware(thunk['withExtraArgument'](api)));
}
示例9: routerMiddleware
import { syncHistoryWithStore, routerReducer, routerMiddleware, push, replace } from 'react-router-redux';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { browserHistory } from 'react-router';
import thunk from 'redux-thunk';
import promiseMiddleware from 'redux-promise-middleware';
import CurrentUser from './reducers/authorize/reducer';
import UsersRepository from './reducers/users/usersReducer';
const middleware = routerMiddleware(browserHistory);
let reudcers = combineReducers({
CurrentUser,
UsersRepository,
routing: routerReducer,
});
const logger = store => next => action => {
console.log('dispatching', action);
let result = next(action);
console.log('next state', store.getState());
return result;
};
export var store = createStore<store.IApplicationStore>(reudcers, applyMiddleware(middleware, thunk, promiseMiddleware(), logger));
export var navigate = (path: string): void => {
store.dispatch(replace(path));
};
示例10: it
it('does not broadcast queries when non-apollo actions are dispatched', (done) => {
const query = gql`
query fetchLuke($id: String) {
people_one(id: $id) {
name
}
}
`;
const variables = {
id: '1',
};
const data1 = {
people_one: {
name: 'Luke Skywalker',
},
};
const data2 = {
people_one: {
name: 'Luke Skywalker has a new name',
},
};
const networkInterface = mockNetworkInterface(
{
request: { query, variables },
result: { data: data1 },
},
{
request: { query, variables },
result: { data: data2 },
}
);
function testReducer (state = false, action) {
if (action.type === 'TOGGLE') {
return true;
}
return state;
}
const client = new ApolloClient();
const store = createStore(
combineReducers({
test: testReducer,
apollo: client.reducer(),
}),
applyMiddleware(client.middleware())
);
const queryManager = new QueryManager({
networkInterface,
store: store,
reduxRootKey: 'apollo',
});
const handle = queryManager.watchQuery({
query,
variables,
});
let handleCount = 0;
const subscription = handle.subscribe({
next(result) {
handleCount++;
if (handleCount === 1) {
assert.deepEqual(result.data, data1);
return subscription.refetch();
} else if (handleCount === 2) {
assert.deepEqual(result.data, data2);
store.dispatch({
type: 'TOGGLE',
});
}
assert.equal(handleCount, 2);
done();
},
});
});