Cannot use nodeBind API at runtime with Polymer transformer

64 views
Skip to first unread message

jolleekin

unread,
Jul 8, 2014, 5:58:20 AM7/8/14
to w...@dartlang.org
I was trying to bind the text of a button to a resource string.
nodeBind(button.firstChild).bind('text', 'resources.commands.save');


This in turn creates a PathObserver, which then creates a PropertyPath. PropertyPath uses smoke.nameToSymbol to convert each path segment into a Symbol. 

The created PropertyPath was expected to have 3 symbols: #resources, #commands, and #save, but it actually contained #resources, null, and null.

Before transformation, smoke.nameToSymbol uses new Symbol(name); however, after transformation, smoke.nameToSymbol calls GeneratedSymbolConverterService.nameToSymbol, which uses a symbol cache. The cache didn't contain #commands and #save, so nodeBind failed.

/// Implements [SymbolConverterService] using a static configuration.
class GeneratedSymbolConverterService implements SymbolConverterService {
 
Map<Symbol, String> _names;


 
/// A map from strings to symbols (the reverse of [names]).
 
final Map<String, Symbol> _symbols;


 
GeneratedSymbolConverterService(StaticConfiguration configuration)
     
: _names = configuration.names,
        _symbols
= {} {
    _names
.forEach((k, v) { _symbols[v] = k; });
 
}


 
String symbolToName(Symbol symbol) => _names[symbol];
  Symbol nameToSymbol(String name) => _symbols[name];
}



Günter Zöchbauer

unread,
Jul 8, 2014, 1:38:25 PM7/8/14
to w...@dartlang.org
Interesting, also didn't work for others 

Siggi Cherem

unread,
Jul 8, 2014, 4:05:09 PM7/8/14
to w...@dartlang.org
Yeah, the problem is that all these bindings and PathObservers are actually reflective. We use smoke as a library that implements the reflective API. When you run in Dartium, this API is implemented with dart:mirrors, but when you build the app with the polymer transformers, we replace the use of mirrors with generated code to help dart2js optimize your app.

To generate the code we need, the polymer transformers parse your app and discover every expression in a template, among other things. Expressions within Dart code, like your example above, are not discovered so we don't know how to generate code for them. That's basically why there is no entry for #commands or #save.

In the future I'd like to add the option of adding your own transformer phase that tells smoke to generate some extra symbols and such, but this is not available today.

Meanwhile, the best way to work around this issue is to make sure those symbols are mentioned in your HTML templates somewhere. It should be enough to define a polymer-element element whose template uses those symbols (even if the element is not used anywhere).

Cheers,
Siggi


--
You received this message because you are subscribed to the Google Groups "Dart Web Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web+uns...@dartlang.org.
Visit this group at http://groups.google.com/a/dartlang.org/group/web/.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/web/62196b48-1dc0-4a0a-afe0-ee0047332147%40dartlang.org.

jolleekin

unread,
Jul 9, 2014, 10:37:57 AM7/9/14
to w...@dartlang.org
The generated symbol converter service GeneratedSymbolConverterService caches all static symbols. My question is: Can this cache be grown at run-time instead? It's not desirable to declare all symbols statically if there are hundreds of them, for example.

Siggi Cherem

unread,
Jul 9, 2014, 1:18:41 PM7/9/14
to w...@dartlang.org
It is not today, but it will be in the future.  I have a pending CL that will make this a bit more flexible: https://codereview.chromium.org/362043006/


--
You received this message because you are subscribed to the Google Groups "Dart Web Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web+uns...@dartlang.org.
Visit this group at http://groups.google.com/a/dartlang.org/group/web/.
Reply all
Reply to author
Forward
0 new messages