New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug? Model-to-target converter is called multiple times. #9405

Open
chrisch-hh opened this Issue Oct 11, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@chrisch-hh

chrisch-hh commented Oct 11, 2017

Take a look at this playground example: http://tinyurl.com/y9w9knuk

I've bound a store model to a form controller model with a converter function. The converter function is called multiple times (see the console log). The first times it is called with null, the last time it is called with the correct value. I don't know if its a bug or if its the intended behavior or my mistake, but I think the converter function should be called only once.

@chrisch-hh

This comment has been minimized.

Show comment
Hide comment
@chrisch-hh

chrisch-hh Oct 12, 2017

And another thing: The signature of the converter function according to the SingleValueBinding is:

converter : function(data, model, source, target) {};

But the model parameter is always undefined in my playground example...?

chrisch-hh commented Oct 12, 2017

And another thing: The signature of the converter function according to the SingleValueBinding is:

converter : function(data, model, source, target) {};

But the model parameter is always undefined in my playground example...?

@cajus

This comment has been minimized.

Show comment
Hide comment
@cajus

cajus Oct 12, 2017

Contributor

@chrisch-hh that's because you've an undefined model initially. Change

      // add converter to firstName binding
      controller.addBindingOptions("firstName", model2target, target2model);

      // bind store model with form controller model
      store.bind("model", controller, "model");

to

      // bind store model with form controller model
      store.bind("model", controller, "model");
      
      // add converter to firstName binding
      controller.addBindingOptions("firstName", model2target, target2model);

in order to have an initialized model. Your converter will be only called once in this case. The reason is that the property chaining tries to resolve a "null" source and then runs into a fallback.

Contributor

cajus commented Oct 12, 2017

@chrisch-hh that's because you've an undefined model initially. Change

      // add converter to firstName binding
      controller.addBindingOptions("firstName", model2target, target2model);

      // bind store model with form controller model
      store.bind("model", controller, "model");

to

      // bind store model with form controller model
      store.bind("model", controller, "model");
      
      // add converter to firstName binding
      controller.addBindingOptions("firstName", model2target, target2model);

in order to have an initialized model. Your converter will be only called once in this case. The reason is that the property chaining tries to resolve a "null" source and then runs into a fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment