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 combineMiddlewares = middlewares => (store) => { | |
| const propagationFunctions = middlewares.map(middleware => ( | |
| middleware(store) | |
| )); | |
| const invokeMiddlewareChain = propagationFunctions.reduceRight((nextFn, propagationFunction) => ( | |
| propagationFunction(nextFn) | |
| ), null); | |
| return invokeMiddlewareChain; | |
| }; |
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 createStore = ({ middlewares = [] }) => { | |
| const store = {}; | |
| store.dispatch = combineMiddlewares(middlewares)(store); | |
| return store; | |
| }; |
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 reducerMiddleware = (reducer, initialState) => store => { | |
| let state = initialState; | |
| store.getState = () => state; | |
| return () => (action) => { state = reducer(state, action); }; | |
| }; |
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 createStore = ({ | |
| reducer = state => state, | |
| middlewares = [], | |
| initialState = undefined, | |
| }) => { | |
| const store = {}; | |
| store.dispatch = combineMiddlewares([ | |
| ...middlewares, | |
| reducerMiddleware(reducer, initialState) |
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 subscribeMiddleware = () => store => { | |
| let handlers = []; | |
| store.subscribe = (cb) => { | |
| handlers = handlers.concat(cb); | |
| const removeSubscriber = () => { handlers = handlers.filter(fn => fn !== cb) }; | |
| return removeSubscriber; | |
| }; | |
| return next => (action) => { |
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
| if condition { | |
| doSomething(); | |
| } |
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
| export default function () { | |
| return { | |
| manipulateOptions(opts, parserOpts) { | |
| parserOpts.plugins.push("jsx"); | |
| } | |
| }; | |
| } |
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 { plugins } = require('babylon/lib/parser'); | |
| const pluginName = 'swift-blocks'; | |
| const plugin = createSwiftBlocksPlugin(); | |
| plugins[pluginName] = 'swift-blocks'; | |
| module.exports = () => ({ | |
| manipulateOptions(opts, parserOpts) { | |
| parserOpts.plugins.push(pluginName); | |
| }, |
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
| pp.parseStatement = function (declaration, topLevel) { | |
| let node = this.startNode(); | |
| if (this.match(tokenTypes._if)) { | |
| return this.parseIfStatement(node); | |
| } else { | |
| ... | |
| } | |
| } |
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 plugin = (instance) => { | |
| instance.extend('parseIfStatement', inner => function (node) { | |
| this.next(); | |
| const isParenFree = this.match(tokenTypes.parenL); | |
| node.test = isParenFree | |
| ? this.parseExpression() | |
| : this.parseParenExpression(); | |
| node.consequent = isParenFree | |
| ? this.parseBlock(false) |