when-js

Need correct call to Promise reduce (when.reduce )

十年热恋 提交于 2020-01-05 07:21:26
问题 I have a processor function that takes a "cmd" object and returns a promise where the resolution is the same "cmd" object passed in (with a response key added). reduce here is when.reduce reduce = require('when').reduce; //return processor(cmds[0]) return reduce(cmds, function(processor, cmd) { Debug.L1('running processor for component ', cmd.component) return processor(cmd) }) .then(cmds => { Debug.L1('cmds with responses\n', cmds) let response = cmds.map(cmd => { return cmd.response })

$.when($(“”).function() == true).then() not working as expected

本秂侑毒 提交于 2019-12-25 12:02:44
问题 I have a function which returns true or false. Now I'd like to execute some code once the function returns "true". The function determines if an element is visible on screen. I took it from here. The element is displayed 1-2 seconds after the page is loaded. But as this is also related to the internet connection of the user, I don't want to use a setTimout function. I tried a few things and found out, that it works in an if/else statement, but not in a when/then. Any ideas, what is going

How to run get json and save as a variable, then use it in other methods

怎甘沉沦 提交于 2019-12-25 02:22:56
问题 I want to parse a JSON file, then store its data in a variable and use it in different part of the code. I think for this purpose I should use $.when().done() . However, I I do not know how to pass data. The following code is not function but it shows what I am trying to achieve. var myJSON; function _parseJSON() { $.getJSON(settings.json_src).done(function(data) { return data; }); } $.when(_parseJSON()).done(function() { myJSON = data; }); function _cacheOptions() { console.log(myJSON.data);

Getting dependencies to load correctly in requirejs (autobahn and whenjs)

柔情痞子 提交于 2019-12-08 05:06:15
问题 I have been stuck on this problem for the past few hours. I'm trying to get autobahnjs and whenjs to be loaded correctly by requirejs. require.config({ paths: { angular: '../bower_components/angular/angular', angularBootstrap: '../bower_components/angular-bootstrap/ui-bootstrap', bootstrap: '../bower_components/bootstrap/dist/js/bootstrap', jquery: '../bower_components/jquery/jquery', chosen: '../bower_components/chosen/chosen.jquery.min', text: '../bower_components/requirejs-text/text',

trap when.js unhandled rejections

二次信任 提交于 2019-12-07 03:30:40
问题 I'd like to trap when.js unhandled rejections so that I can log them. To accomplish this I've overriden console.warn(), however that can log stuff other than when.js which I'm not interested in. ref: https://github.com/cujojs/when/blob/master/docs/api.md#debugging-promises I am using prettymonitor with when.js https://github.com/AriaMinaei/pretty-monitor 回答1: If you're on the server-side, you can use the promise rejection hooks. These will work on most promise implementations on the server

trap when.js unhandled rejections

拥有回忆 提交于 2019-12-05 07:20:44
I'd like to trap when.js unhandled rejections so that I can log them. To accomplish this I've overriden console.warn(), however that can log stuff other than when.js which I'm not interested in. ref: https://github.com/cujojs/when/blob/master/docs/api.md#debugging-promises I am using prettymonitor with when.js https://github.com/AriaMinaei/pretty-monitor If you're on the server-side, you can use the promise rejection hooks. These will work on most promise implementations on the server-side (io.js, bluebird, when, etc): process.on("unhandledRejection", function(promise, reason){ // deal with