Skip to content

Instantly share code, notes, and snippets.

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 / connect.jsx
Created September 8, 2018 18:23
Detailed explanation of the new React context
export const connect = selector => target => ({ children, ...props }) => {
let updateFromParent = true;
let cachedState = null;
let cachedComponent = null;
return (
<Consumer>
{context => {
const state = selector(context, props);
if (!updateFromParent && (state === cachedState || shallowCompare(state, cachedState))) {
updateFromParent = false;
@artalar
artalar / example.jsx
Created September 8, 2018 18:24
Detailed explanation of the new React context
const store = {
observedBits: {
foo: 0b01,
bar: 0b10
},
state: {
foo: 1,
bar: 1,
},
update(cb) {
@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";
@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;
/*[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

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