-
-
Save OliverJAsh/079c47d10e3c720b768865f89666ddb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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