This file contains hidden or 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
# Your init script | |
# | |
# Atom will evaluate this file each time a new window is opened. It is run | |
# after packages are loaded/activated and after the previous editor state | |
# has been restored. | |
# | |
# An example hack to log to the console when each text editor is saved. | |
# | |
# atom.workspace.observeTextEditors (editor) -> | |
# editor.onDidSave -> |
This file contains hidden or 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
export const someAsyncAction((someArg) => somePromise, (state, {loading, error, data}) => state.doSomething); | |
// later on | |
someComponentBeforeLoad={someAsyncAction} |
This file contains hidden or 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
// SomeComponent.js | |
import incrementCounter from 'counter/actions'; // example | |
<Button onClick={incrementCounter(10)} | |
// counter/actions.js | |
import {createAction} from 'actionFactory'; | |
export function incrementCounter((state, count) => state.counter += count); | |
// actionFactory.js |
This file contains hidden or 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
// useage of screating asyncAction | |
// first argument is Promise provider - it needs to return some promise that will be resolved | |
// 2nd argument is function that will change the state. This function is called 2 times - 1. when action is called, 2. when promise is resolved or rejected | |
// 1st argument of this function is current state and 2nd argument is data in a form: | |
// {loading: true/false, data: undefined/promiseResult, error: false/promiseError} | |
export const getPostComments = createAsyncAction((postId) => { | |
return someApi.getPostCommentsPromise(postId); | |
}, (state, payload, postId) => { | |
// postId is just argument passed | |
payload.loading; // if promise is resolved or not |
NewerOlder