當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript redux.createStore函數代碼示例

本文整理匯總了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"));
}
開發者ID:creimers,項目名稱:Farmbot-Web-API,代碼行數:3,代碼來源:store.ts

示例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) => '',
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:redux-first-router-tests.ts

示例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();
開發者ID:Lavoaster,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:redux-batched-subscribe-tests.ts

示例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
	})
}
開發者ID:HansS,項目名稱:angular2-samples-jason-aden,代碼行數:25,代碼來源:store.ts

示例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'));
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:32,代碼來源:react-router-redux-tests.ts

示例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
  ],
開發者ID:moyesh,項目名稱:killer-game-web-ng2,代碼行數:31,代碼來源:app.module.ts

示例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,
  ),
);
開發者ID:MasterLemon2016,項目名稱:LeanMood,代碼行數:12,代碼來源:index.ts

示例8: configureStore

export function configureStore() {
    return createStore(rootReducer, defaultState, applyMiddleware(thunk['withExtraArgument'](api)));
}
開發者ID:get-focus,項目名稱:focus-help-center,代碼行數:3,代碼來源:index.ts

示例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));
};
開發者ID:arborQ,項目名稱:TypeGetInvolved,代碼行數:29,代碼來源:index.ts

示例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();
      },
    });

  });
開發者ID:Aweary,項目名稱:apollo-client,代碼行數:81,代碼來源:QueryManager.ts


注:本文中的redux.createStore函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。