- "Laws" test suite: run flowtyped functions to verify that a "monoid" (for example) really follows the laws for its
empty
andconcat
operations.
Last active
January 15, 2017 19:55
-
-
Save xaviervia/e4b6a94f294d4057d4f0cae228833030 to your computer and use it in GitHub Desktop.
2017-01-15 notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Session = { | |
username: Maybe String | |
authToken: String | |
} | |
type State = LoginState | IndexState | AlbumState | |
type LoginState = { | |
type: Symbol.for('Login'), | |
username: String, | |
password: String | |
} | |
type RouteAction = { | |
type: Symbol.for('ROUTE'), | |
payload: DOMLocation | |
} | |
coreReducer = (state, action) => { | |
switch (action.type) { | |
case 'ROUTE': | |
return | |
default: | |
switch (state.type) { | |
case 'Login': | |
return loginReducer(state, action) | |
case | |
} | |
} | |
} | |
({next}) => {window.app = next} | |
state, | |
actions: [ | |
{ | |
type: atom('LOCATION'), | |
payload: | |
} | |
] | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <script> | |
if (document && document.body) { document.body.innerHTML = '' } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const location = arrow((reducer) => arrow((state, action) => { | |
return reducer(state, action) | |
})) | |
const reducer = compose( | |
location, | |
auth | |
)(x => x) | |
reduce((state, action) | |
({state, action}) | |
Action Location -> Reducer -> Effects | |
const dom = () => { | |
let onSubmit = (e) => next({type: 'LOGIN', ...}) | |
cell(({state, next}) => { | |
return { | |
View: state.session != null ? state.location : LoginComponent, | |
onSubmit | |
...stuff | |
} | |
}, cell(({View, ...stuff}) => element(View, stuff), cell(render, id)) | |
const dom = cell(({state}) => { | |
return state.location | |
}, cell((location) => { | |
return { | |
type: 'div', | |
props: [], | |
children: [ | |
{text: location} | |
] | |
} | |
}, cell((tree) => | |
render(tree, document.getElementById('root')), | |
id | |
))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const render = (tree, target) => {} | |
if (typeof tree === 'string') return target.appendChild | |
const element = document.createElement(tree.type) | |
tree.children.forEach( | |
cell :: (f -> a) -> lens -> cell -> b | |
lensedCell :: (lens, f) -> x -> | |
let theNext = () => {} | |
const onClick = () => theNext({type: 'CLICK'}) | |
const effectCell = (effect, child) => { | |
let theNext = () => {} | |
const listener = effect(theNext) | |
return cell(({next, state}) => { | |
theNext = next | |
return listener(state) | |
}, child) | |
} | |
effectCell((next) => (state) => {}) | |
effectCell((next) => (state) => ({ | |
type: 'div', | |
props: [{name: 'onClick', value: onClick}], | |
children: [] | |
}), | |
cell( | |
loopArrow((prev, next) => equals(prev, next) ? prev : next, {}), | |
(element) => render(element, document.getElementById('root')) | |
) | |
) | |
cell( | |
loopArrow((prev, next) => equals(prev, next) ? prev : next, {}), | |
(element) => render(element, document.getElementById('root')) | |
) | |
const effect = (effect) => { | |
let theNext = () => {} | |
const listener = effect(theNext) | |
return ({next, state}) => { | |
theNext = next | |
return listener(state) | |
}) | |
} | |
effect((next) => cell((state) => ({ | |
type: 'div', | |
props: [{name: 'onClick', value: onClick}], | |
children: [] | |
}), | |
cell( | |
loopArrow((prev, next) => equals(prev, next) ? prev : next, {}), | |
(element) => render(element, document.getElementById('root')) | |
)) | |
) | |
effect( | |
(next) => { | |
const onClick = () => next({type: 'CLICKED'}) | |
return cell((state) => ({ | |
type: 'div', | |
props: [{name: 'onClick', value: onClick}], | |
children: [] | |
}), | |
cell( | |
loopArrow((prev, next) => equals(prev, next) ? prev : next, {}), | |
(element) => render(element, document.getElementById('root')) | |
)) | |
} | |
) | |
toEffect = (a -> b -> c) -> (a, b) | |
const alsdfjasdf = toEffect(stateful => stateless => console.log(stateful, stateless)) | |
alsdfjasdf({a: 2}, 6) | |
alsdfjasdf({a: 2}, 6) | |
alsdfjasdf(next, state) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {arrow} from 'zazen/arrow' | |
import { | |
apply, | |
compose, | |
map, | |
flatten | |
} from 'ramda' | |
const store = arrow( app => ({ | |
...app, | |
state: app.actions.reduce(app.reducer, app.state) | |
})) | |
const next = previous_app => (...actions) => { | |
return actions.length > 0 ? | |
app({...previous_app, actions}) : | |
previous_app | |
} | |
const app = store | |
.pipe( app => ({ | |
...app, | |
next: next(app) | |
}) ) | |
.pipe( ({state, next, effects}) => { | |
return compose( | |
apply(next), | |
flatten, | |
map( e => e({state, next}) ) | |
)(effects) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment