Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

fix(parser): Allow access to Map properties in expressions #605

Closed

Conversation

chalin
Copy link
Contributor

@chalin chalin commented Feb 24, 2014

E.g. map.keys, map.length, etc. This is a proposed solution to #394.

@@ -647,6 +647,16 @@ main() {
});


it('should evaluate map item and field access', () {
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor Author

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.

@vicb
Copy link
Contributor

vicb commented Feb 25, 2014

@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)

@chalin
Copy link
Contributor Author

chalin commented Feb 25, 2014

@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?)

@vicb
Copy link
Contributor

vicb commented Feb 25, 2014

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.

@chalin
Copy link
Contributor Author

chalin commented Feb 26, 2014

Thanks for the link to the "perils of rebasing". Would it be best to cancel this PR and resubmit a new one?

@vicb
Copy link
Contributor

vicb commented Feb 26, 2014

Would it be best to cancel this PR and resubmit a new one?

why ?

@chalin
Copy link
Contributor Author

chalin commented Feb 26, 2014

Because this PR now muddles the commits actually belonging to this PR with those that were brought in via the rebase.

@vicb
Copy link
Contributor

vicb commented Feb 26, 2014

don't know exactly what happened with this PR. You should check the git graph log.
A force push should be enough if really required (it will mess history), no need to re-open a new PR.

@chalin
Copy link
Contributor Author

chalin commented Feb 26, 2014

Wouldn't it be preferable to open a new PR than to mess with history?

@vicb
Copy link
Contributor

vicb commented Feb 26, 2014

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)

@mhevery
Copy link
Contributor

mhevery commented Mar 6, 2014

Sorry, that this PR got stale. Could you rebase it to the latest codebase?

@chalin
Copy link
Contributor Author

chalin commented Mar 6, 2014

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?

@vicb
Copy link
Contributor

vicb commented Mar 6, 2014

Patrice, have you checked this doc

@chalin
Copy link
Contributor Author

chalin commented Mar 6, 2014

Thanks for the pointer Vic!

@chalin
Copy link
Contributor Author

chalin commented Mar 8, 2014

Having looked at the code it seems that any watched expression that produces a new (non identical()) object that is not a String, will fail to stabilize under the new change detection algorithm (CDA).

@vicb, @mhevery, can you confirm?

If so, then while map properties like length can be supported, but map.keys and map.values will not be useful under the next CDA.

@mhevery
Copy link
Contributor

mhevery commented Mar 13, 2014

That is correct, and that is by intention. Strings have an exception due to the way Strings work in JS.

@mhevery
Copy link
Contributor

mhevery commented Mar 13, 2014

Should this be kept open, or closed?

@chalin
Copy link
Contributor Author

chalin commented Mar 13, 2014

Open. I think it would still be useful to support, e.g., map.length. And one of your comments on another thread gave me an idea about dealing with map.keys. If you agree, I'll clean this PR up.

@chalin
Copy link
Contributor Author

chalin commented Mar 14, 2014

Done. (Actually, this is pretty much the solution as committed on Feb 27. In the interim I had been trying to get map.keys to work which I now know isn't possible under the current CDA.)

@@ -424,7 +425,9 @@ class DirtyCheckingRecord<H> implements Record<H>, WatchRecord<H> {
return;
}

if (obj is Map) {
if (obj is Map && (!isMapProperty(field)
Copy link
Contributor

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 ?

@vicb
Copy link
Contributor

vicb commented Mar 14, 2014

Could you please follow guidelines for commit comments (and probably squash them ?)

@chalin
Copy link
Contributor Author

chalin commented Mar 14, 2014

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.

@vicb
Copy link
Contributor

vicb commented Mar 14, 2014

@chalin I don't know about GH app (I'm running on Ubuntu) - git-cola is very nice but of course no GH integration.

@chalin
Copy link
Contributor Author

chalin commented Mar 15, 2014

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',
Copy link
Contributor

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 ?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

@vicb
Copy link
Contributor

vicb commented Mar 17, 2014

@chalin are there usecases for .values and .keys ? souldn't we only implement a | keys filter instead ?

@vicb
Copy link
Contributor

vicb commented Mar 17, 2014

@chalin if the commit comment is right, we could access a random key with map.key or map['key'] ?

Then there could be a confusion for keys which have the same name as a map property. What about accessing properties with . only and keys with [] only, as in Dart ?

@chalin
Copy link
Contributor Author

chalin commented Mar 17, 2014

I agree with you entirely: which is why I had opened #606, Treat Dart maps like maps, not (JavaScript) objects with field access.

@vicb
Copy link
Contributor

vicb commented Mar 17, 2014

@chalin I would prefer to see:

  • support for keys and values removed (as it could cause confusion for now)
  • using only [] to access map keys (and . for map property).

May be you can submit an other PR that could be merged soon and then we'll discuss the remaining points ?

@chalin
Copy link
Contributor Author

chalin commented Mar 17, 2014

@vicb:

support for keys and values removed (as it could cause confusion for now)

Done.

using only [] to access map keys (and . for map property).

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?

May be you can submit an other PR that could be merged soon and then we'll discuss the remaining points ?

Yes.

@vicb
Copy link
Contributor

vicb commented Mar 17, 2014

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?

probably a good idea.

There is still an indentation issue, otherwise LGTM

@chalin
Copy link
Contributor Author

chalin commented Mar 17, 2014

Oups, forgot about it.
Done.

…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”]`.
@mhevery
Copy link
Contributor

mhevery commented Mar 19, 2014

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.

@mhevery mhevery closed this Mar 19, 2014
@chalin
Copy link
Contributor Author

chalin commented Mar 19, 2014

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 (!isMapProperty(name)) would need to be removed to be in full alignment with your step 1.

@chalin chalin deleted the patch-0224-map-property-access branch March 20, 2014 03:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

3 participants