dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
181 stars 33 forks source link

`clear('propertyName')` seems not to work #587

Closed zoechi closed 8 years ago

zoechi commented 9 years ago
  @property final List<String> matchingCandidates = ['x'];

  @eventHandler
  void findCandidates(Event event, _) {
    clear('matchingCandidates');
...

The null object does not have a getter 'length'.

NoSuchMethodError: method not found: 'length' Receiver: null Arguments: []

0 Object._noSuchMethod (dart:core-patch/object_patch.dart:42)

1 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)

2 HtmlElement&PolymerMixin&PolymerBase.clear (package:polymer_interop/src/polymer_base.dart:330:62)

3 MyElement.findCandidates (http://localhost:63342/polymer-dart-patterns/web/forms/implementing_simple_autocompletion/my_element.dart:85:5)

4 Function._apply (dart:core-patch/function_patch.dart:7)

5 Function.apply (dart:core-patch/function_patch.dart:28)

6 _InstanceMirrorImpl.invoke (package:reflectable/src/reflectable_transformer_based.dart:161:23)

7 _setupEventHandlerMethods.. (package:polymer/src/common/polymer_descriptor.dart:151:31)

The debugger shows this before the clear('matchingCandidates'); line is executed:

matchingCandidates: [x]

jakemac53 commented 9 years ago

Sounds like jsElement['matchingCandidates'] is null, can you confirm? If the dart/js lists got out of sync then I probably need a bit more context to figure out how that happened.

zoechi commented 9 years ago

jsElement['matchingCandidates'] returns [] at the location where clear('matchingCandidates'); fails.

Sorry, forgot to add the link. Here is the full example (with a workaround and added TODOs where I run into the issue) https://github.com/bwu-dart-contributing/polymer-dart-patterns/blob/0.17.0/web/forms/implementing_simple_autocompletion/my_element.dart

I also forgot to mention that addAll('matchingCandidates', candidates); also fails (with jsElement['matchingCandidates'] being [])

Unhandled exception: TypeError: Cannot read property 'length' of undefined

0 JsObject._callMethod (dart:js:678)

1 JsObject.callMethod (dart:js:618)

2 HtmlElement&PolymerMixin&PolymerBase.addAll (package:polymer_interop/src/polymer_base.dart:324:15)

3 MyElement.Eval. (evaluate:source:2:1)

4 MyElement.findCandidates. (http://localhost:63342/polymer-dart-patterns/web/forms/implementing_simple_autocompletion/my_element.dart:105:7)

5 _RootZone.runUnary (dart:async/zone.dart:1165)

6 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:502)

7 _Future._propagateToListeners (dart:async/future_impl.dart:585)

8 _Future._completeWithValue (dart:async/future_impl.dart:376)

9 _Future._asyncComplete. (dart:async/future_impl.dart:430)

10 _microtaskLoop (dart:async/schedule_microtask.dart:43)

11 _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)

12 _ScheduleImmediateHelper._handleMutation (dart:html:42565)

jakemac53 commented 9 years ago

This appears just to be related to using a final field, without matchingCandidates being marked as final both methods work (for me at least).

jakemac53 commented 9 years ago

Also, fwiw this looks like its resolved in the no-proxy branch which takes a pretty different approach to this sort of thing. That should be merged in the next few days.

jakemac53 commented 8 years ago

This should be working fine on the 1.0.0-rc.1 branch.