A tiny (265 byte) utility to create state machine components using two pure functions.
The API is a single function that accepts 2 pure functions as arguments:
| import {Phased} from 'recondition'; | |
| // Adds a lovely fade in of the modal | |
| // and a gentle slide-down of the modal content | |
| class Demo extends React.Component { | |
| state = { showDialog: false }; | |
| render() { | |
| return ( | |
| <div> | |
| <button onClick={() => this.setState({ showDialog: true })}> | |
| Show Dialog |
| import React from 'react'; | |
| import debounce from 'utils/debounce'; | |
| class EmailInput extends React.Component { | |
| checkEmail = value => { | |
| // only check if the field passes Yup email validation first | |
| if ( | |
| !this.props.form.errors[this.props.name].includes( | |
| 'invalid' /* or whatever your error message is*/ | |
| ) |
A tiny (265 byte) utility to create state machine components using two pure functions.
The API is a single function that accepts 2 pure functions as arguments:
| # Name it whatever you want. I like `y` because in my keyboard layout it's close to `;` | |
| function y() { | |
| previous=$? | |
| if [ $previous -eq 0 ]; then | |
| osascript -e "display notification \"Done\" with title \"Terminal Task\"" && say "it is done"; | |
| else | |
| osascript -e "display notification \"Failed\" with title \"Terminal Task\"" && say "it went to the trees"; | |
| fi | |
| } |
| const t = require("tcomb"); | |
| // imstruct is a tcomb type builder that internally builds an | |
| // Immutable.Record object, but applies tcomb's type system to it | |
| const imstruct = require("../util/imstruct"); | |
| const Person = imstruct({ | |
| name: t.String, | |
| age: t.Number | |
| }); |
A complete list of RxJS 5 operators with easy to understand explanations and runnable examples.
| import { createStore, applyMiddleware } from 'redux'; | |
| import { Observable, Subject } from 'rxjs'; | |
| const api = type => { | |
| console.log(`calling API ${type}`); | |
| return new Promise(res => setTimeout(() => res(), 500)); | |
| }; | |
| const actionOrder = (actions, order) => actions.every((action, index) => action.type === order[index]); | |
| const actionPredicate = actions => filterableAction => actions.some(action => action === filterableAction.type); |
| (function () { | |
| var makeCallback = function(eventType, observer) { | |
| if (eventType === 'value') { | |
| return function(snap) { | |
| observer.onNext(snap); | |
| }; | |
| } else { | |
| return function(snap, prevName) { | |
| // Wrap into an object, since we can only pass one argument through. | |
| observer.onNext({snapshot: snap, prevName: prevName}); |