A mistate is a Javascript data structure with a schema, underlying immutable data structure, lensing, and efficient subscriber abilities.
The schema format is the same as GraphQL.
Here's an example:
const a = { | |
foo: "bar", | |
beep: { | |
boop: 1, | |
}, | |
baz: [ | |
true, | |
] | |
}; |
const choice = (decision) => { | |
let yes = () => {}; | |
let no = () => {}; | |
const a = { | |
yes: (f) => { yes = f; return a; }, | |
no: (f) => { no = f; return a; }, | |
decide: () => { | |
const next = decision() ? yes() : no(); | |
return next.decide ? next.decide() : next; | |
} |
let set = (cache, val, k, ...rest) => { | |
if (rest && rest.length) { | |
if (!cache.has(k)) { | |
cache.set(k, new Map()); | |
} | |
set(cache.get(k), val, ...rest); | |
} else { | |
cache.set(k, val); | |
} | |
}; |
1. Choose your boundary | |
2. Identify state | |
3. Test *just* the boundary | |
4. Any test that will be maintained (non-TDD) should have a positive and negative test | |
5. Unit tests can be thrown away at will | |
6. DRY/inheritance is usually bad in test code, especially if stateful | |
7. Try to colocate data and code as much as possible | |
8. Make randomness and time explicit | |
9. It’s best to write tests FIRST |
start :: ApiGateway -> Request -> Response | |
create :: forall i, o. | |
{ | |
method, | |
path, | |
intReq: Async (HTTPRequest -> i), | |
lambda: Async (i -> Tuple o Status), | |
intRes: Status -> o -> Async HTTPResponse | |
} -> ApiGateway | |
-- problems: does o differ per status but need to be synced between 7/8? |
A mistate is a Javascript data structure with a schema, underlying immutable data structure, lensing, and efficient subscriber abilities.
The schema format is the same as GraphQL.
Here's an example:
var good = {a: {b: {c: 1}}} | |
console.log(new Maybe(good).bind(t=>t.a).bind(t=>t.b).bind(t=>t.c).getOrElse(2)) | |
var bad = {a: 3} | |
console.log(new Maybe(bad).bind(t=>t.a).bind(t=>t.b).bind(t=>t.c).getOrElse(2)) |
stream { | |
... on Text { | |
html | |
} | |
... on Photo { | |
url | |
} | |
... on CodeSnippet { | |
embedSrc | |
} |
import { Map, is } from 'immutable' | |
import { createStore, bindActionCreators } from 'redux' | |
import { connect } from 'react-redux' | |
import { pure } from 'recompose' | |
// ACTIONS | |
const INCREMENT_ACTION = "INCREMENT_ACTION" | |
const LOAD_AUTHOR = "LOAD_AUTHOR" | |
const increment = () => ({type: INCREMENT_ACTION}) | |
const loadAuthor = (id, data) => ({type: LOAD_AUTHOR, id, ...data}) |