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 store = { | |
| actions: { | |
| play: (dispatch, payload, actions) => { | |
| // do some action | |
| // payload --> 'abc' | |
| dispatch('play', 'arg1', 'arg2') | |
| } | |
| }, | |
| reducer: { | |
| play: (_) => ({ ..._ }) |
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 blockOne = (funcName) => { | |
| if (funcName === 'one') { | |
| return false | |
| } | |
| } | |
| const emitEvent = (funcName) => { | |
| console.log('[event] ' + funcName) | |
| } |
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 usePrevious(value) { | |
| const ref = useRef() | |
| useEffect(() => { | |
| ref.current = value | |
| }, [value]) | |
| return ref.current | |
| } |
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 machine = { | |
| empty: { | |
| SELECT: { | |
| to: 'loading', | |
| action: (state, dispatch) => { | |
| interval.stop() | |
| loadBook().then((book) => dispatch('SELECT_SUCCESS', book)) | |
| return { ...state, title: null, progress: 0 } | |
| }, | |
| }, |
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 prop(value, path) { | |
| path = path | |
| .replace(/\[(\d)\]/g, (_, v) => '.' + v) | |
| .replace(/^\./, '') | |
| .split('.') | |
| let current = value | |
| for (let prop of path) { | |
| if (current[prop]) current = current[prop] | |
| else return current[prop] | |
| } |
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 getGlobals = (() => { | |
| const diff = (a, b) => a.filter((v) => !b.includes(v)) | |
| const windowProps = JSON.parse( | |
| '["window","self","document","name","location","customElements","history","locationbar","menubar","personalbar","scrollbars","statusbar","toolbar","status","closed","frames","length","top","opener","parent","frameElement","navigator","origin","external","screen","innerWidth","innerHeight","scrollX","pageXOffset","scrollY","pageYOffset","visualViewport","screenX","screenY","outerWidth","outerHeight","devicePixelRatio","clientInformation","screenLeft","screenTop","defaultStatus","defaultstatus","styleMedia","onsearch","isSecureContext","performance","onappinstalled","onbeforeinstallprompt","crypto","indexedDB","webkitStorageInfo","sessionStorage","localStorage","onbeforexrselect","onabort","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","o |
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 timeTaken = | |
| (fn) => | |
| async (...args) => { | |
| console.time(fn.name); | |
| const res = await fn(...args); | |
| console.timeEnd(fn.name); | |
| return res; | |
| }; |
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
| <div id="app"></div> | |
| <script> | |
| const $ = (...args) => { | |
| if (args.length > 1) args.reverse() | |
| const [query, parent = document] = args | |
| return Array.from(parent.querySelectorAll(query)) | |
| } | |
| $.create = (html) => { |
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 createInterval = () => { | |
| let interval = null | |
| const start = (cb, delay) => !interval && (interval = setInterval(cb, delay)) | |
| const stop = () => { | |
| clearInterval(interval) | |
| interval = null | |
| } | |
| return { start, stop } | |
| } |
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 SORT_STRATEGIES = { | |
| asc: (a, b) => (a - b > 0 ? 1 : -1), | |
| desc: (a, b) => (a - b < 0 ? 1 : -1), | |
| }; | |
| const pipe = (...fns) => | |
| fns.reduce( | |
| (f, g) => | |
| (...args) => | |
| g(f(...args)) |