Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created September 10, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverJAsh/079c47d10e3c720b768865f89666ddb8 to your computer and use it in GitHub Desktop.
Save OliverJAsh/079c47d10e3c720b768865f89666ddb8 to your computer and use it in GitHub Desktop.
// index.ts
import * as actions from './actions';
import { render } from './render';
import { configureAndCreateStore } from './store';
const wait = (ms: number) =>
new Promise<void>(resolve => setTimeout(resolve, ms));
const example = async () => {
const store = configureAndCreateStore();
const renderWithState = () => {
const state = store.getState();
const renderResult = render(state);
console.log({ renderResult });
};
renderWithState();
store.subscribe(renderWithState);
// Simulate actions
store.dispatch(actions.search({ query: 'dogs' }));
await wait(1000);
actions.searchSuccess({
items: [{ id: 'english-setter' }, { id: 'irish-setter' }],
});
await wait(1000);
store.dispatch(actions.search({ query: 'cats' }));
await wait(1000);
store.dispatch(actions.searchFailure());
};
example().catch(error => {
console.error(error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment