-
Notifications
You must be signed in to change notification settings - Fork 78
Implement Iterable Support #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Awesome! Sorry I dropped the ball on responding to this, but I'm taking a look and of course we want to get this added :) |
@@ -211,3 +225,48 @@ function convertTimezone(tz) { | |||
} | |||
return false; | |||
} | |||
|
|||
function isArrayLike(val) { | |||
if (!iterableSupport && Array.isArray(val)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it is not expected that the state of iterableSupport
would change at runtime, is that correct? If so, it is possible to simply split apart this functions into two versions instead of checking the iterableSupport
boolean constantly? I am seeing a bit of a performance dip in production from this PR, and I'm not 100% sure where it is coming from (it's running in an environment where iterableSupport === false
), but when I simply changed these functions to only have the iterableSupport === false
code, it helped bring it pretty much all the way back up to previous levels.
map.forEach(function(val, key) { | ||
object[key] = val; | ||
}); | ||
// if custom toString was implemented, attach to new object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive me for not fully understanding Map
objects, but what is the purpose of this? Is it even performent to constantly create new Map()
over and over again?
@@ -25,6 +26,15 @@ test('SqlString.escapeId', { | |||
assert.equal(SqlString.escapeId(['a', 'b', 't.c']), "`a`, `b`, `t`.`c`"); | |||
}, | |||
|
|||
'sets are turned into lists': function() { | |||
if (!iterableSupport) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically it is best that if a test is going to be skipped, it's simply just not added to the object so it doesn't show up like there is a test happening. At least, the pattern with utest
, which does not have a skip mechanism.
var set = new Set(); | ||
set.add('a'); | ||
set.add('b'); | ||
var sql = SqlString.format('? and ?', set); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, what? I don't think this makes sense. I don't think a top-level Set
object should act like an array, because isn't a Set
order independent? The top-level is very much order-dependent.
Hi @krmannix do you think you'll get a chance to take a look at the review comments? |
Hi @dougwilson - will try to do this upcoming weekend! Sorry I've dropped the ball on responding - thanks for taking the time to review it. |
@dougwilson going to close this, and if I can find a cleaner implementation I'll reopen. Thanks again for the time you took reviewing! |
Attempts to implement support for es6 iterables like
Map
andSet
, to fix #1422.Set
should behave like anArray
,Map
should behave like anObject
.