Skip to content

Instantly share code, notes, and snippets.

@gryzzly
Last active August 29, 2015 14:27
Show Gist options
  • Save gryzzly/b260a9d89eaad8bbf84c to your computer and use it in GitHub Desktop.
Save gryzzly/b260a9d89eaad8bbf84c to your computer and use it in GitHub Desktop.
requirebin sketch
var createRedux = require('redux').createRedux;
var reducer = function (state, action) {
return state;
};
var redux = createRedux(reducer);
redux.dispatch({
type: 'FOO',
payload: {}
});
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";exports.__esModule=true;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var _createDispatcher=require("./createDispatcher");var _createDispatcher2=_interopRequireDefault(_createDispatcher);var _utilsComposeStores=require("./utils/composeStores");var _utilsComposeStores2=_interopRequireDefault(_utilsComposeStores);var _middlewareThunk=require("./middleware/thunk");var _middlewareThunk2=_interopRequireDefault(_middlewareThunk);var Redux=function(){function Redux(dispatcher,initialState){_classCallCheck(this,Redux);var finalDispatcher=dispatcher;if(typeof dispatcher==="object"){finalDispatcher=(0,_createDispatcher2["default"])((0,_utilsComposeStores2["default"])(dispatcher),function(getState){return[(0,_middlewareThunk2["default"])(getState)]})}this.state=initialState;this.listeners=[];this.replaceDispatcher(finalDispatcher)}Redux.prototype.getDispatcher=function getDispatcher(){return this.dispatcher};Redux.prototype.replaceDispatcher=function replaceDispatcher(nextDispatcher){this.dispatcher=nextDispatcher;this.dispatchFn=nextDispatcher(this.state,this.setState.bind(this))};Redux.prototype.dispatch=function dispatch(action){return this.dispatchFn(action)};Redux.prototype.getState=function getState(){return this.state};Redux.prototype.setState=function setState(nextState){this.state=nextState;this.listeners.forEach(function(listener){return listener()});return nextState};Redux.prototype.subscribe=function subscribe(listener){var listeners=this.listeners;listeners.push(listener);return function unsubscribe(){var index=listeners.indexOf(listener);listeners.splice(index,1)}};return Redux}();exports["default"]=Redux;module.exports=exports["default"]},{"./createDispatcher":2,"./middleware/thunk":4,"./utils/composeStores":7}],2:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=createDispatcher;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _utilsComposeMiddleware=require("./utils/composeMiddleware");var _utilsComposeMiddleware2=_interopRequireDefault(_utilsComposeMiddleware);var INIT_ACTION={type:"@@INIT"};function createDispatcher(store){var middlewares=arguments[1]===undefined?[]:arguments[1];return function dispatcher(initialState,setState){var state=setState(store(initialState,INIT_ACTION));function dispatch(action){state=setState(store(state,action));return action}function getState(){return state}var finalMiddlewares=typeof middlewares==="function"?middlewares(getState):middlewares;return _utilsComposeMiddleware2["default"].apply(undefined,finalMiddlewares.concat([dispatch]))}}module.exports=exports["default"]},{"./utils/composeMiddleware":6}],3:[function(require,module,exports){"use strict";exports.__esModule=true;var _bind=Function.prototype.bind;exports["default"]=createRedux;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _Redux=require("./Redux");var _Redux2=_interopRequireDefault(_Redux);function createRedux(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}var redux=new(_bind.apply(_Redux2["default"],[null].concat(args)));return{subscribe:redux.subscribe.bind(redux),dispatch:redux.dispatch.bind(redux),getState:redux.getState.bind(redux),getDispatcher:redux.getDispatcher.bind(redux),replaceDispatcher:redux.replaceDispatcher.bind(redux)}}module.exports=exports["default"]},{"./Redux":1}],4:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=thunkMiddleware;function thunkMiddleware(getState){return function(next){var recurse=function recurse(action){return typeof action==="function"?action(recurse,getState):next(action)};return recurse}}module.exports=exports["default"]},{}],5:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=bindActionCreators;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _utilsMapValues=require("../utils/mapValues");var _utilsMapValues2=_interopRequireDefault(_utilsMapValues);function bindActionCreators(actionCreators,dispatch){return(0,_utilsMapValues2["default"])(actionCreators,function(actionCreator){return function(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}return dispatch(actionCreator.apply(undefined,args))}})}module.exports=exports["default"]},{"../utils/mapValues":8}],6:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=composeMiddleware;function composeMiddleware(){for(var _len=arguments.length,middlewares=Array(_len),_key=0;_key<_len;_key++){middlewares[_key]=arguments[_key]}return middlewares.reduceRight(function(composed,m){return m(composed)})}module.exports=exports["default"]},{}],7:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=composeStores;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _utilsMapValues=require("../utils/mapValues");var _utilsMapValues2=_interopRequireDefault(_utilsMapValues);var _utilsPick=require("../utils/pick");var _utilsPick2=_interopRequireDefault(_utilsPick);function composeStores(stores){var finalStores=(0,_utilsPick2["default"])(stores,function(val){return typeof val==="function"});return function Composition(atom,action){if(atom===undefined)atom={};return(0,_utilsMapValues2["default"])(finalStores,function(store,key){return store(atom[key],action)})}}module.exports=exports["default"]},{"../utils/mapValues":8,"../utils/pick":9}],8:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=mapValues;function mapValues(obj,fn){return Object.keys(obj).reduce(function(result,key){result[key]=fn(obj[key],key);return result},{})}module.exports=exports["default"]},{}],9:[function(require,module,exports){"use strict";exports.__esModule=true;exports["default"]=pick;function pick(obj,fn){return Object.keys(obj).reduce(function(result,key){if(fn(obj[key])){result[key]=obj[key]}return result},{})}module.exports=exports["default"]},{}],redux:[function(require,module,exports){"use strict";exports.__esModule=true;function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _createRedux=require("./createRedux");var _createRedux2=_interopRequireDefault(_createRedux);var _createDispatcher=require("./createDispatcher");var _createDispatcher2=_interopRequireDefault(_createDispatcher);var _utilsComposeMiddleware=require("./utils/composeMiddleware");var _utilsComposeMiddleware2=_interopRequireDefault(_utilsComposeMiddleware);var _utilsComposeStores=require("./utils/composeStores");var _utilsComposeStores2=_interopRequireDefault(_utilsComposeStores);var _utilsBindActionCreators=require("./utils/bindActionCreators");var _utilsBindActionCreators2=_interopRequireDefault(_utilsBindActionCreators);exports.createRedux=_createRedux2["default"];exports.createDispatcher=_createDispatcher2["default"];exports.composeMiddleware=_utilsComposeMiddleware2["default"];exports.composeStores=_utilsComposeStores2["default"];exports.bindActionCreators=_utilsBindActionCreators2["default"]},{"./createDispatcher":2,"./createRedux":3,"./utils/bindActionCreators":5,"./utils/composeMiddleware":6,"./utils/composeStores":7}]},{},[]);var createRedux=require("redux").createRedux;var reducer=function(state,action){return state};var redux=createRedux(reducer);redux.dispatch({type:"FOO",payload:{}});
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"redux": "0.12.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment