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
| (function(global) { | |
| global.AOP = function(subject) { | |
| return { | |
| after(method, advice) { | |
| const original = subject[method]; | |
| subject[method] = function() { | |
| const result = original.apply(this, arguments); |
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 sortable = function(data) { | |
| const table = document.createElement('table'); | |
| const thead = document.createElement('thead'); | |
| const tbody = document.createElement('tbody'); | |
| const currentOrder = {}; | |
| // Function to populate the tbody with the data | |
| const _populate = current => { | |
| const row = tbody.insertRow(); |
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
| ;(function init (global) { | |
| 'use strict' | |
| // Constructor function, initialise states and actions | |
| global.Container = function constructor (initialState) { | |
| this._states = initialState === undefined ? [] : [initialState] | |
| this._actions = {} | |
| } | |
| // Get the current state |
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
| function run (iterator) { | |
| // Kick off the promise chain | |
| Promise.resolve().then( | |
| function resolved (value) { | |
| // Get the next yielded iterator step, | |
| // passing in the value from the last | |
| // fulfillment | |
| const next = iterator.next(value) |
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
| // Placeholder | |
| const _ = function _ () {} | |
| // Curry a given function, optionally specifying | |
| // a context on which it should finally get called | |
| const curry = function curry (fn, thisArg) { | |
| // Accumulate the call arguments for the curried function | |
| return function accumulate () { |
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 curry = (fn, thisArg) => function accumulate (...args) { | |
| return args.length < fn.length | |
| ? accumulate.bind(null, ...args) | |
| : fn.apply(thisArg, args) | |
| } | |
| const fn = (a, b, c) => a + b + c | |
| curry(fn)(1)(2)(3) // 6 | |
| curry(fn)(1)(2, 3) // 6 etc... |
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 make = function make ({ | |
| proto = {}, | |
| self = {}, | |
| init = function init (obj) { | |
| Object.assign(this, obj) | |
| return this | |
| }, | |
| mixins = [] | |
| }) { | |
| const mixProto = {} |
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
| /** | |
| * A collection of helper prototype for everyday DOM traversal, manipulation, | |
| * and event binding. Sort of a minimalist jQuery, mainly for demonstration | |
| * purposes. MIT @ m3g4p0p | |
| */ | |
| window.$ = (function (undefined) { | |
| /** | |
| * Duration constants | |
| * @type {Object} |
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 = (function () { | |
| const scope = new WeakMap | |
| const storeProto = { | |
| subscribe (prop, fn) { | |
| const ownScope = scope.get(this) | |
| ownScope.subscribers[prop] = ownScope.subscribers[prop] || [] | |
| ownScope.subscribers[prop].push(fn) |
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
| /** | |
| * In JavaScript, we can only return one value from a function. | |
| * | |
| * This restricts piping to unary functions -- we couldn't pipe, say, | |
| * both the request and the response object, or the error and the data | |
| * argument from one function to the next without wrapping them in | |
| * another object or an array. Yuck. | |
| * | |
| * So we can't return them both, but we could call another function | |
| * with both! Ok, now we just wrapped them in another function instead |