-
Notifications
You must be signed in to change notification settings - Fork 248
fix(parser): Allow access to Map properties in expressions #605
Conversation
@@ -647,6 +647,16 @@ main() { | |||
}); | |||
|
|||
|
|||
it('should evaluate map item and field access', () { |
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.
Unfortunately this is only half the work. Same kinds of tests also have to work on scope watching, and I think right now, they would fail. Could you create a scope.watch('may.isEmpty') test to make sure it works there as well. Change detection takes a different path.
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.
Ok. Will try to find previous example of a scope.watch()
test as an example (probably in scope_spec.dart
).
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.
Done for map properties whose values are of a primitive type like map.length
, map.isEmpty
. Still need to work on map.keys
and map.values
but that will have to wait until midday tomorrow.
@chalin you should prepend "[WIP]" to the title of PRs which are work in progress. (And you should merge master into this judging by the commit diff list) |
@vicb : thanks for letting me know about the process; I edited the title to start with "[WIP]". (As for your other comment, you are suggesting that I merge rather than rebase master into my branch?) |
rebasing is not preferred for "long running" branches, which I why I would advice merging master into your branch. You can still rebase later when the code stabilizes and the PR is ready to be merged into master. |
Thanks for the link to the "perils of rebasing". Would it be best to cancel this PR and resubmit a new one? |
why ? |
Because this PR now muddles the commits actually belonging to this PR with those that were brought in via the rebase. |
don't know exactly what happened with this PR. You should check the git graph log. |
Wouldn't it be preferable to open a new PR than to mess with history? |
Up to you but this one already has some linked issues & comments so I would keep it (and some commits might disappear from the diff once master is merged here) |
Sorry, that this PR got stale. Could you rebase it to the latest codebase? |
Yes, that is the plan. I would like to understand the new change detection alg first though ... any chance that this post might get answered soon? |
Patrice, have you checked this doc |
Thanks for the pointer Vic! |
Having looked at the code it seems that any watched expression that produces a new (non @vicb, @mhevery, can you confirm? If so, then while map properties like |
That is correct, and that is by intention. Strings have an exception due to the way Strings work in JS. |
Should this be kept open, or closed? |
Open. I think it would still be useful to support, e.g., |
Done. (Actually, this is pretty much the solution as committed on Feb 27. In the interim I had been trying to get |
@@ -424,7 +425,9 @@ class DirtyCheckingRecord<H> implements Record<H>, WatchRecord<H> { | |||
return; | |||
} | |||
|
|||
if (obj is Map) { | |||
if (obj is Map && (!isMapProperty(field) |
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.
||
should be moved up - maybe everything fits 80 chars ?
Could you please follow guidelines for commit comments (and probably squash them ?) |
I took a few tries (GitHub app wasn't helping), but I think I managed to squash the commits, fix if condition to fit on one line and adjusted the commit message. |
@chalin I don't know about GH app (I'm running on Ubuntu) - git-cola is very nice but of course no GH integration. |
I'm just falling back the cmd line most of the time now. Might give git-cola a try, thanks. Btw, anything else for me to do on this PR that is preventing it from being merged? |
@@ -101,6 +101,11 @@ main(arguments) { | |||
'items[1].name', | |||
'list[3] = 2', | |||
'map["square"] = 6', | |||
'map.isEmpty', | |||
'map.isNotEmpty', | |||
'map.keys', |
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.
should keys and values still be here ?
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.
Yes: I have a small proposal to share with the team related to .keys
and .values
. Do you still want me to take them out for now?
|
||
String lookup(String key) { | ||
String name = _computeName(key); | ||
if (helpers.containsKey(key)) return name; | ||
helpers[key] = isReservedWord(key) | ||
? templateForReserved(name, key) | ||
: isMapProperty(key) && templateWithoutMapTest != null | ||
? templateWithoutMapTest(name, key) |
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.
indentation
@chalin are there usecases for |
@chalin if the commit comment is right, we could access a random key with Then there could be a confusion for keys which have the same name as a map property. What about accessing properties with |
I agree with you entirely: which is why I had opened #606, Treat Dart maps like maps, not (JavaScript) objects with field access. |
@chalin I would prefer to see:
May be you can submit an other PR that could be merged soon and then we'll discuss the remaining points ? |
Done.
Agreed, but I worry that such a change would be controversial and hence delay this PR from being merged even more. Would you mind if I did this work under #606?
Yes. |
probably a good idea. There is still an indentation issue, otherwise LGTM |
Oups, forgot about it. |
…ions Allow access to all `Map` properties like `map.length`, except for `keys` and `values`. Introduces changes to parser and change detection. Breaking change: map keys matching `Map` property names will now need to be accessed as, e.g., `map[“length”]`.
I apologize for taking so long to respond to this. See my current thinking here: #397 (comment) I am going to close this PR because it is not aligned with the direction as explained in the comment above. |
Ok np, but if you take a quick look at the diff (+53/-8 lines) most of this PR is in support of your Step 1 since it adds tests to confirm that map field access works. only 3 tests ( |
E.g.
map.keys
,map.length
, etc. This is a proposed solution to #394.