Skip to content
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

ref is not updated when an if.bind changes state. #532

Closed
RichTeaTime opened this issue Mar 3, 2017 · 1 comment
Closed

ref is not updated when an if.bind changes state. #532

RichTeaTime opened this issue Mar 3, 2017 · 1 comment
Assignees
Labels

Comments

@RichTeaTime
Copy link

I'm submitting a bug report

  • Library Version:
    1.0.5

  • Language:
    TypeScript 2.0.3

Current behavior:

On an element which uses if.bind and ref:

<div if.bind="showApp" ref="theelement">
    This is the element.
</div>

As expected, when the if.bind evaluates to 'false', the 'ref' attribute on it (or below it), evaluates to undefined.

Changing the property so that the if.bind now evaluates to 'true' causes the element to be shown.
However, the 'theelement' property remains undefined for a significant period of time after the assignment is changed.

Expected/desired behavior:

When the if.bind becomes true, the ref should be set. Or there should be a simple way to trigger code when the ref has been assigned (bindings? taskqueue?)

https://gist.run/?id=29c33d2954d53945a0361eca79666e39

What is the motivation / use case for changing the behavior?

Using show.bind (which does leave the ref set, because the Element already exists) causes code to be executed when it isn't required. Being able to if.bind an element, have it come into existence based on binding changes, and then be able to refer to that element from the view-model is vital for simple, easy to read code.

@jdanyow
Copy link
Contributor

jdanyow commented Mar 12, 2017

This is working as designed. Recommend refactoring your code such that the logic that depends on the DOM element is in a custom element or custom attribute instead of trying to synchronize multiple bindings (if and ref).

Another option would be to use a property setter for theelement. Then you'll know exactly when it's assigned.

_theelement = null;
get theelement() {
  return this._theelement;
}
set theelement(value) {
  this._theelement = value;
  // do the stuff you needed to do
}

@jdanyow jdanyow closed this as completed Mar 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants