Last active
December 15, 2015 16:19
-
-
Save deniswolf/5288647 to your computer and use it in GitHub Desktop.
build on idea of promises
POC of framework full of chained callbacks
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
// kommunism.js | |
// build on false promises | |
// to chain callbacks | |
function PrimitiveKommunism(computationFunction, thisArg){ | |
// todo: return promise that will resolve when computation is done | |
var someInnerComputationsResult = computationFunction.apply(thisArg, _.toArray(arguments)); | |
function Kommunism(currentCallback, optionalCallbackParameters){ | |
var currentArguments = _.toArray(arguments).slice(1); | |
var argumentsToPass = [someInnerComputationsResult].concat(currentArguments); | |
currentCallback.apply(this,argumentsToPass); | |
return Kommunism; | |
} | |
return Kommunism; | |
} | |
function callBack(){ | |
console.log('callback',arguments); | |
} | |
socialism = new PrimitiveKommunism(function(){return 'Wait for the future, Komrade!'}) | |
socialism(callBack,'z','x')(callBack)(callBack,1)(callBack,2)(callBack,3); |
and on line 13:
I would like to know which context it is better to pass :/
why do you need _
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that was the simple part,
now there is a next step ahead - how to make this system work with the promises across the whole flow
in a way that:
when I do some computations, they could end in a distant future
but all the callbacks will still receive them as promises or callback will be run on promises' resolves