GithubHelp home page GithubHelp logo

Comments (8)

jmesserly avatar jmesserly commented on July 18, 2024

edited subject. Based on your link, I think the issue is property paths like obj["+foo"] don't currently work.

from observe-js.

jolleekin avatar jolleekin commented on July 18, 2024

No, obj["+foo"] works perfectly. What doesn't work is obj["foo"] and obj[1] if obj is a Map

Why `obj["+foo"] works

obj["+foo"] is correctly parsed into [#obj, "+foo"]

Why obj["foo"] doesn't work

obj["foo"] is parsed into [#obj, #foo] instead of [#obj, "foo"], and #foo may not exist in generated code

Why obj[1] doesn't work if obj is a Map

_getObjectProperty and _setObjectProperty only handle List indexers and ignore Map integer indexers.

_getObjectProperty(object, property) {
  if (object == null) return null;

  if (property is int) {
    if (object is List && property >= 0 && property < object.length) {
      return object[property];
    }
  } else if (property is String) {
    return object[property];
  } else if (property is Symbol) {
  ...
}

bool _setObjectProperty(object, property, value) {
  if (object == null) return false;

  if (property is int) {
    if (object is List && property >= 0 && property < object.length) {
      object[property] = value;
      return true;
    }
  } else if (property is Symbol) {
  ...
}

This problem results from a difference between JS and Dart. In JS, obj.foo and obj["foo"] are identical while, in Dart, they are two completely different things. So not everything that works in JS can work in Dart.

To fix this problem, the parser should reserve indexers (whether they are Map indexers or List indexers) instead of trying to convert them into symbols.

  • identifiers => symbols
  • string indexers => strings
  • int indexers => int's

from observe-js.

jmesserly avatar jmesserly commented on July 18, 2024

@jolleekin I think you're talking about Dart-specific issues. Those are tracked at https://code.google.com/p/dart/issues/detail?id=20294

from observe-js.

jmesserly avatar jmesserly commented on July 18, 2024

(This issue tracker is only for issues related to the JavaScript implementation)

from observe-js.

jolleekin avatar jolleekin commented on July 18, 2024

I know. The problem is observe-dart is implemented based on observe-js. If something doesn't work in the Dart implementation, it must be reflected back to the JS implementation. That's why I opened this issue.

Sent from my Windows Phone


From: John Messerlymailto:[email protected]
Sent: ‎8/‎12/‎2014 1:46 AM
To: Polymer/observe-jsmailto:[email protected]
Cc: Man Hoangmailto:[email protected]
Subject: Re: [observe-js] PathObserver doesn't support String keys in index expressions (#64)

(This issue tracker is only for issues related to the JavaScript implementation)


Reply to this email directly or view it on GitHub:
#64 (comment)

from observe-js.

jmesserly avatar jmesserly commented on July 18, 2024

Ah, gotcha. But I wouldn't say it so strongly. There can be differences, if it makes sense. For example, in the case of Map, it's a Dart type and doesn't need (and couldn't) be handled in JavaScript. Same thing with Symbol vs String. That should be addressed in the Dart code (https://code.google.com/p/dart/issues/detail?id=20294). That's why for this bug, we focus only on problems that can be recreated in JavaScript.

from observe-js.

jolleekin avatar jolleekin commented on July 18, 2024

Maybe I took sigmund's words too serious ("that is also how the JS implementation is written. We have to follow up with them to make sure we are consistent."). Anyway, if the Dart team agrees there can be differences, this issue can be closed.

from observe-js.

rafaelw avatar rafaelw commented on July 18, 2024

Ok. I'm closing this. If someone feels there is an actual bug in the JS impl, please post a jsbin with expected/actual behavior.

from observe-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.