Skip to content

Instantly share code, notes, and snippets.

View b2whats's full-sized avatar
🎯
Focusing

Akimov Vladimir b2whats

🎯
Focusing
View GitHub Profile
@maheshsenni
maheshsenni / hmr.js
Created May 12, 2016 01:08
Step 3b - Creating a module bundler with Hot Module Replacement
/* 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
@tj
tj / update.js
Last active April 29, 2023 14:53
shouldComponentUpdate utility
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())
@taion
taion / async-props-style.js
Last active January 24, 2017 17:14
React Router data fetching
// Define your components like:
class MyComponent extends React.Component {
static fetchData = (params) => {
// return an action here.
};
/* ... */
}
function fetchComponentData(component, store, params) {
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,
//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');
@btroncone
btroncone / rxjs_operators_by_example.md
Last active May 3, 2026 02:38
RxJS 5 Operators By Example
@jonahwilliams
jonahwilliams / index.js
Last active August 5, 2016 03:02
Redux with Rxjs
"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
@jgoux
jgoux / helpers.js
Last active April 6, 2016 16:21
redux-loop helpers
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}`
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);
@xgrommx
xgrommx / ranges.js
Last active June 13, 2020 23:04
Generate ranges in javascript
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)));