Skip to content

Instantly share code, notes, and snippets.

View pie6k's full-sized avatar

Adam Pietrasiak pie6k

View GitHub Profile
// 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
// 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
export const someAsyncAction((someArg) => somePromise, (state, {loading, error, data}) => state.doSomething);
// later on
someComponentBeforeLoad={someAsyncAction}
@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 ->
@pie6k
pie6k / keymap.cson
Last active May 15, 2017 14:42
It allows moving cursor in atom without moving your hand away to arrow keys. I think it might be useful for people typing with all fingers.
'atom-text-editor:not([mini])':
'cmd-shift-j': 'core:move-left'
'cmd-shift-k': 'core:move-down'
'cmd-shift-l': 'core:move-up'
'cmd-:': 'core:move-right' # it's cmd-shift-; (shift + ; = :)
.monaco-shell {
font-family: 'Lucida Grande', sans-serif;
}
.monaco-split-view > .split-view-view > .header {
text-transform: none;
}
@pie6k
pie6k / .gitconfig
Last active July 6, 2017 21:31
My configs
[alias]
# short aliases
st = status
co = checkout
ci = commit
cm = commit -m
br = branch
df = diff
lg = log -p
rso = remote show origin
@pie6k
pie6k / readme.md
Created September 22, 2017 15:39 — forked from jakewtaylor/readme.md
VS Code CSS addition to increase readability on file tree.

Increases indentation on the file tree and adds some lines to each directory/file.

Works 15 levels deep, but you can expand it by just adding more of each line thats repeating, i.e.:

  • add another box shadow
    • (n*-20px) 0 0 0 rgba(255, 255, 255, 0.4)
  • add another padding-left
    • .monaco-tree-row[aria-level="n"] { padding-left: ((n-1)*20)px; }
  • add another :before & :after with left positioning
    • .monaco-tree-row[aria-level="n"]:before { left: (((n-1)*20)-9)px; }
  • .monaco-tree-row[aria-level="n"]:after { left: (((n-1)*20)-9)px; }
@pie6k
pie6k / actions.ts
Last active April 23, 2020 12:31
Better way to create type-safe Redux actions and reducers with Typescript
interface LoginData {
email: string;
password: string;
}
export interface UserData {
id: string;
email: string;
profilePicture: string;
}
@pie6k
pie6k / entity.ts
Created March 27, 2018 12:36
Integration: typegql and typeorm
import { Entity, BaseEntity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { ObjectType, Field } from 'typegql';
@Entity()
@ObjectType()
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
@Field()
id: number;