This file contains 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 server = new FluxServer(8080); | |
const messageList = server.Store('/messageList'); | |
messageList.set('nextId', 0).commit(); | |
const postMessage = server.Action('/postMessage') | |
.onDispatch(({ nickname, message }) => { | |
messageList.set(messageList.get('nextId') + 1, { nickname, message }) | |
.set('nextId', messageList.get('nextId') + 1) | |
.commit() | |
}); |
This file contains 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 client = new FluxClient('http://localhost:8080'); | |
const messageList = client.Store('/messageList'); | |
const postMessage = client.Action('/postMessage'); | |
const MessageList = React.createClass({ | |
getInitialState() { | |
return { messageList: this.props.messageList.head, message: null }; | |
}, | |
componentDidMount() { | |
messageList.onUpdate(({ head }) => this.setState({ messageList: head })); |
This file contains 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
// is A an extension of B ? | |
// ex: | |
// class C extends Oject {} | |
// class B extends C {} | |
// class A extends B {} | |
// isExtension(A, B) === true | |
// isExtension(A, C) === true | |
// isExtension(A, Object) === true | |
// isExtension(B, A) === false | |
function isExtensionOf(A, B) { |
This file contains 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 TransformProps = (Component, transform) => class extends React.Component { | |
displayName = Component.displayName; | |
render() { | |
return <Component {...transform(this.props)}>; | |
} | |
}; | |
const transform = (f) => (t) => { | |
r = {}; |
This file contains 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
@component(() => ({ | |
users: ['remote://users', {}], | |
})) | |
@component(({ users }) => | |
users.mapKeys((userId) => | |
[`user:${userId}`, [`remote://users/${userId}`, { firstName: 'John', lastName: 'Doe' }]] | |
).toObject() | |
) | |
class UserList extends React.Component { | |
render() { |
This file contains 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
Show hidden characters
{ | |
"always_show_minimap_viewport": true, | |
"bold_folder_labels": true, | |
"color_scheme": "Packages/Oceanic Next Color Scheme/Oceanic Next.tmTheme", | |
"copy_with_empty_selection": true, | |
"ensure_newline_at_eof_on_save": true, | |
"font_family": "Consolas", | |
"font_options": "subpixel_antialias", | |
"highlight_line": true, | |
"highlight_modified_tabs": true, |
This file contains 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
let x; | |
class A { | |
constructor() { | |
this.a = true; | |
// explictly returns this | |
return this; | |
} | |
} |
This file contains 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 $x = Symbol(); | |
const t = { $x: 4, y: 5, z: 6 }; | |
const { [$x], ...collect } = t; // collect = { y: 5, z: 6 } |
This file contains 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 willUnmount = Symbol('unmount'); | |
function statefulComponent(getInitialState, render, componentWillUnmount = () => void 0) { | |
return function*(props) { | |
const internalId = React.pleaseGiveMeAnInternalId(); | |
const state = getInitialState(props); | |
const setState = (nextState) => { | |
Object.assign(state, nextState); | |
React.pleaseRerenderThisInternalId(internalId); | |
}; |
This file contains 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 match, { $, $$$ } from 'match-with'; | |
// l is a list | |
const length = match(l).with( | |
// $() is a single-item named placeholder | |
// $$$() is a rest-collecting named placeholder | |
// .when(predicate) adds a guard predicate | |
clause([$('head'), $$$('tail')]).when(({ tail }) => tail.length > 0)).then(({ head, tail }) => 1 + tail.length), |