Mehdi
Mehdi

Reputation: 43

Polymer with one way databinding

I tried to look for answer to my questions but it seems I cannot find any information on one way data-binding with Polymer.

I have been looking into Polymer and find many of its facets very interesting. I however wonder whether it's possible to "use" polymer in a different way. Different than how I see it being used in examples and tutorials.

Is it possible to use one way binding from the model to the view only (and not from the view to the model)?. How about no binding at all?

One could obviously create extra variables in the model and update the "real parts of the model" in a more controlled manner. But maybe there are some sort of backed-in one way binding alternatives?

The other thing that makes me hesitate with jumping on the Polymer train is the way integration is done between polymer components. Are there alternatives to using the declarative integration/composition. Can one compose different polymer components in a more controlled manner (i.e. programmatically).

I'm pretty sure the above is possible. But can it be done in an elegant way? Has anyone tried such approach?

For instance, knockout offers some beforechange event to allow for more controls on updating the observables. But this ugly "work around" makes the whole process cumbersome.

Thanks in advance for any help!

Upvotes: 4

Views: 1128

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657278

update

In Polymer 1.x [[]] is for one-way binding.

original

Have a look at the official Polymer documentation.

One-time bindings

Sometimes, you may not need dynamic bindings. For these cases, there are one-time bindings.

Anywhere you use ¸{{}} in expressions, you can use double brackets ([[]]) to set up a one-time binding. The binding becomes inactive after {{site.project_title}} sets its value for the first time.

Example:

<input type="text" value="this value is inserted once: [[ obj.value ]]">

One time bindings can potentially be a performance win if you don't need the overhead of setting up property observation.

See also https://code.google.com/p/dart/issues/detail?id=21022

Upvotes: 2

Related Questions