Created
September 12, 2024 15:49
-
-
Save DIY0R/c52737b9d1870fc232e539394a892ace to your computer and use it in GitHub Desktop.
This file contains 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 chain(prev = null) { | |
const cur = () => { | |
if (cur.prev) { | |
cur.prev.next = cur; | |
cur.prev(); | |
} else { | |
cur.forward(); | |
} | |
}; | |
cur.prev = prev; | |
cur.fn = null; | |
cur.args = null; | |
cur.do = (fn, ...args) => { | |
cur.fn = fn; | |
cur.args = args; | |
return chain(cur); | |
}; | |
cur.forward = () => { | |
if (cur.fn) cur.fn(cur.args, () => { | |
if (cur.next) cur.next.forward(); | |
}); | |
}; | |
return cur; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment