Hello, everybody.
when I was reading the source code of throttle, I can't understand the usage of line 861 to line 864.
sorry, My English is not good, but I will try to describe my question clearly.
My question is "if remaining <= 0
is true
, why still need call clearTimeout()
to cancel the timer ?"
In my opnion, if remaining <= 0
is true
, It means timeout
must be null
or undefined
. So It don't need to call clearTimeout()
.
If you can give me a hand, I'll be appriciated.
Can you share a screenshot of the actual usage?
I might be able to do that. One sec.
It's probably something funny with the data, but a screenshot of the usage might help rule out any silly errors.
Yeah, I wanted to make sure I was expecting the right stuff to happen.
Nope, that didn't work.
So that's the code, being debugged. You can see "theseOrders" is an array of non-empty objects.
Hmm, that url doesn't work for me
Can you just drag it into Gitter?
imgpsh_fullsize.png
imgpsh_fullsize.png
And there's the result of checking what "thisOrder" is. I expected it to be one of the non-empty objects. Is that a correct expectation?
I think it might just be confusion about how the debugger is working
I think you are not yet in the scope of the callback, you are still in the outer scope
It always comes back to scope. What would you recommend?
And thisOrder is not defined in the outer scope.
Just add a few new lines inside your callback so that it's easier to set a breakpoint in there.
Screenshot (1).png
Ah. I see what you mean.
It is populated now in the debugger, but not filtering as I expect it to.
What is the value of thisOrder?
Now that it's populated, it's the same as one of the entries in the theseOrders array.
It could be because I am edgily trying to compare Date Strings.
(is this one bigger than that one, etc.)
Yeah, that's probably not safe
What format is the date string?
one of them is yyyy-mm-dd and the other is yyyy-mm-ddThh:MM:ss
I would add console.log(a, b, a <= b)
My very quick research into ASCII codes told me that would PROBABLY work.
Yeah, it seems dangerous (you should probably try to find a better way), but i would expect it to work as well.
Capture.PNG
Apparently it doesn't work.
I was expecting 0 to evaluate to less than 2.
headdesk
Capture.PNG
That's better. It still doesn't filter out the last two objects from the resulting array, though.
Well, that's all right. It's 5 here. I'm taking off. Thank you for your help!
I think I've got it to a working state. I appreciate it!
Great!
Have a good weekend.
I'm learning cordova right now and trying to use underscore's isEqual function. I understand it comes with cordovalib, does anybody know how i can use it in my index.js?
i also don't usually do webdev
Iām not familiar with Cordovalib. Do you have code you can share?
Fixed it: needed to npm install underscore, then copy underscore-min.js to platforms/[platform]/platform_www and do <script ... src="underscore-min.js"/> in my index.html
@captbaritone I was fetching an object from a server and checking equality locally
working on a custom version of cordova-plugin-fetch and was testing it in an app, so did this in my index.js:
tryFetch: function() {
var parentElement = document.getElementById("fetchjson");
var fetchingElement = parentElement.querySelector('.fetching');
var verifiedElement = parentElement.querySelector('.verified');
var invalidElement = parentElement.querySelector('.invalid');
fetchingElement.setAttribute('style', 'display:block;');
verifiedElement.setAttribute('style', 'display:none;');
invalidElement.setAttribute('style', 'display:none;');
// mvpnFetch should work, cordovaFetch shouldn't
//cordovaFetch('http://server.local/json.json')
mvpnFetch('http://server.local/json.json')
.then(function(response) {
return response.json();
})
.then(function(json) {
console.log(json);
fetchingElement.setAttribute('style', 'display:none;');
if (_.isEqual(json.body, expectedJsonFromFetch)) {
verifiedElement.setAttribute('style', 'display:block');
} else {
invalidElement.setAttribute('style', 'display:block');
}
})
}
const expectedJsonFromFetch = {
"hello": "world",
"number": 1,
"subobject": {
"key": "val"
},
"array": [
"one",
2,
true
]
}
Hello Guys,
I am getting " '_' is not defined no-undef" error. Below is my code.
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
//import AuthorQuiz from './AuthorQuiz';
import Sum from './AuthorQuiz';
function ClickMyButtons({numberOfButtons, onSelection}) {
const makeButton = v => <button key={v} id={v} onClick={event =>
onSelection(event.target.id)}>{v}</button>;
return <div>
{_.range(1, numberOfButtons+ 1).map(makeButton)}
</div>;
}
ReactDOM.render(<ClickMyButtons numberOfButtons={99} onSelection={console.log} />,
document.getElementById('root'));
serviceWorker.unregister();
I did npm install underscore as well, but no luck.
TypeError: Cannot read property 'range' of undefined
, although the first async works.'use strict';
const _ = require ('underscore');
var v = _.range (1, 10);
(async (_) => {
await Promise.all (v.map (async n => {
await console.log (n);
}));
}) ();
(async (_) => {
await Promise.all (_.range (1, 10).map (async n => {
await console.log (n);
}));
}) ();
_.range
should point to the right function and work correctly
const mapLoop = async _ => {
console.log('Start')
const promises = fruitsToGet.map(async fruit => {
const numFruit = await getNumFruit(fruit)
return numFruit
})
const numFruits = await Promise.all(promises)
console.log(numFruits)
console.log('End')
}
async () => {}
Dependency graph of the upcoming modular Underscore (jashkenas/underscore#2849): https://gist.github.com/jgonggrijp/61e9a00b8807cd41a2ffa73b8ad8cc7a/raw/dfc8879dadc1f0691c84a1f1063971067c344775/modular-underscore-dependencies.png
Blue balloons are Object functions, Red is Utility, Orange is Function, Purple is Collection, Green is Array. Yellow arrows indicate direct and indirect dependencies on iteratee
.
// Internal helper to create a simple lookup structure.
// 'collectNonEnumProps' used to depend on '_.contains', but this led to
// circular imports. 'emulatedSet' is a one-off solution that only works for
// arrays of strings.
function emulatedSet(keys) {
var hash = {};
for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
return {
contains: function(key) { return hash[key]; },
push: function(key) {
hash[key] = true;
return keys.push(key);
}
};
}
/********************************************************************************************
* Native code in underscore.js
* "emulatedSet" was called in "collectNonEnumProps", which aim to solve the ieEnumBug
********************************************************************************************/
// Internal helper to create a simple lookup structure.
// `collectNonEnumProps` used to depend on `_.contains`, but this led to
// circular imports. `emulatedSet` is a one-off solution that only works for
// arrays of strings.
function emulatedSet(keys) {
var hash = {};
for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
return {
contains: function(key) { return hash[key]; },
push: function(key) {
hash[key] = true;
return keys.push(key);
}
};
}
var hasEnumBug = !{ toString: null }.propertyIsEnumerable('toString');
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'
];
// Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
// be iterated by `for key in ...` and thus missed. Extends `keys` in place if
// needed.nonEnumerableProps
function collectNonEnumProps(obj, keys) {
keys = emulatedSet(keys);
var nonEnumIdx = nonEnumerableProps.length;
var constructor = obj.constructor;
var proto = Object.prototype.toString.call(constructor) == '[Object Function]' &&
constructor.prototype || Object.prototype;
// Constructor is a special case.
var prop = 'constructor';
if (obj.hasOwnProperty(prop) && !keys.contains(prop)) keys.push(prop);
while (nonEnumIdx--) {
prop = nonEnumerableProps[nonEnumIdx];
if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
keys.push(prop);
}
}
}
/*********************************************************************************
* my test code
*********************************************************************************/
var obj = { toString: null, valueOf: 'value' };
// in IE<9, the keys for obj will be []
var keys = [];
// keys will be [], but we expert ['toString','valueOf']
collectNonEnumProps(obj, keys); // keys = []