A complete list of RxJS 5 operators with easy to understand explanations and runnable examples.
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
| /* This file is included in the page running the app */ | |
| (function() { | |
| // create an instance of Socket.IO for listening | |
| // to websocket messages | |
| var socket = io(); | |
| // listen for 'file-change' message | |
| socket.on('file-change', function(msg) { | |
| console.log('File changed: ' + msg.id); | |
| // download the updated module to kick start |
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
| let rows = {} | |
| export default function(props = [], state = []) { | |
| return function(target) { | |
| const proto = Object.create(target.prototype) | |
| proto.shouldComponentUpdate = function(newProps, newState) { | |
| let id = (this._update_id = this._update_id || Math.random()) |
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
| // Define your components like: | |
| class MyComponent extends React.Component { | |
| static fetchData = (params) => { | |
| // return an action here. | |
| }; | |
| /* ... */ | |
| } | |
| function fetchComponentData(component, store, params) { |
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 React, { PropTypes } from 'react' | |
| import { pure, mapProps, compose, withState, lifecycle, setDisplayName, setPropTypes, defaultProps, onlyUpdateForPropTypes } from 'recompose' | |
| import { repeat } from 'lodash' | |
| export default pure( | |
| compose( | |
| setDisplayName('Loader'), | |
| onlyUpdateForPropTypes, | |
| setPropTypes({ | |
| sign: PropTypes.string, |
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
| //http://widdersh.in/tricycle/ | |
| const Cycle = require('@cycle/core'); | |
| const {makeDOMDriver, div, span, button} = require('@cycle/dom'); | |
| const _ = require('lodash'); | |
| const {Observable} = require('rx'); | |
| const {restartable} = require('cycle-restart'); | |
| function toggle(DOM) { | |
| const toggleEl = DOM.select('.toggle'); | |
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
| "use strict"; | |
| const Rx = require('rx'); | |
| const fetch = require('isomorphic-fetch'); /* use the fetch api on client and server */ | |
| /** | |
| * Given a subreddit, pull down post ids. that is, changing the subreddit by calling terms$.onNext(SUBREDDITNAME) | |
| * automatically calls the reddit api and populates the store. | |
| * To try it out, npm install rx and isomorphic-fetch, then | |
| * var S = require('./index.js'); | |
| * S.store$.subscribe(x => console.log(x)); // listen to every state change |
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 { loop, Effects as E, liftState } from "redux-loop" | |
| import { | |
| cond, pathEq, map, T, reduce, toUpper, pipe, transpose, | |
| lensProp, set as lensSet, view as lensView | |
| } from "ramda" | |
| export const mkInit = (f) => pipe(f, liftState) | |
| export const mkActionType = (namespace) => (type) => `${namespace}/${type}` |
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 { 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); |
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 range1 = len => Object.keys(new Int8Array(len)).map(parseFloat); | |
| const range2 = len => Array.apply(null, {length: len}).map(Number.call, Number); | |
| const range3 = (start, end) => Array.apply(null, Array(end - start)).map((_, i) => start + i); | |
| const range4 = (start, end) => [...Array(end - start)].map((_, i) => start + i); | |
| const range5 = len => Object.keys(Array.apply(null, Array(len))); |