Skip to content

Instantly share code, notes, and snippets.

@artalar
artalar / 1-example.js
Last active October 24, 2018 07:45
pathon v2 RFC
// workflow.js
import {
createReactCreator,
child,
// updateQueue is list of updates priority
// `updateQueue` from `immutablePreset` have `compute` property
// you must use it if you want change react own state before other reactions
updateQueue
} from "pathon/immutablePreset";
const getAsyncType = (type, status) => `${type}_${status}`;
let index = 0;
export const getMasterActionCreator = description => {
const type = `${index++}__${description}`;
const reqType = getAsyncType(type, "REQUEST");
const respType = getAsyncType(type, "SUCCESS");
const errType = getAsyncType(type, "ERROR");
@artalar
artalar / tests.js
Last active October 30, 2018 08:05
stm-5.js
const lib = require('../index');
// ------------------------------------
// -------------- HELPERS -------------
// ------------------------------------
const EFFECT_STATUS = {
idle: 'IDLE',
req: 'REQUEST',
res: 'RESPONSE',
const createConcurrentRequest = () => {
let lastReq;
return async (request, ...params) => {
let myReq = (lastReq = request(...params));
let response = null;
let error = null;
do {
try {
error = null;

Concept

  • layout
    • index.js
    • [ComponentName]
      • index.js
      • ComponentName.js
      • index.test.js
      • index.mdx
  • shared
// implicit cohesions
root = store({ data: { list: [] }, loading: false, error: null })
.on(req, state => ({ ...state, error: null, loading: true }))
.on(res, (state, list) => ({ ...state, data: { list }, loading: false }))
.on(err, (state, error) => ({ ...state, error, loading: false }));
// explicit cohesions
export const data = store({ list: [] })
.on(res, list => ({ list }));
firstName$ = createCaller()
lastName$ = createCaller()
// not lazy
fullName$ = combine(
[firstName$, lastName$],
(_, fn, ln) => [fn, ln].join(' ')
);
displayName$ = combine(
[firstName$, fullName$],
(_, firstN, fullN) => firstN.length < 10 ? fullN : firstN
/*[1]*/import {TextField} from 'material-ui'
// TextField merge props for inner components (outer props and internal props)
<TextField
ownProps={ownProps}
inputProps={{ style: { color: 'black' } }}
placeholderProps={{ style: { color: 'gray' } }}
/>
// VS
function getCaller() {
const stack = getStack();
stack.shift(); // getStack
stack.shift(); // getCaller
// Return caller's caller
return stack;
}
@artalar
artalar / wtf.js
Last active February 4, 2019 09:25 — forked from MichalZalecki/wtf.js
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
/**/ '2' == 2;
//// true
/**/ '2' === 2;