Skip to content

Instantly share code, notes, and snippets.

View pie6k's full-sized avatar

Adam Pietrasiak pie6k

View GitHub Profile
@pie6k
pie6k / init.coffee
Last active July 7, 2017 10:57
My atom settings
# 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 ->
export const someAsyncAction((someArg) => somePromise, (state, {loading, error, data}) => state.doSomething);
// later on
someComponentBeforeLoad={someAsyncAction}
// 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
// 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