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

oneTime binding behavior breaking in a changing collection #301

Closed
blkbltjns opened this issue Jan 21, 2016 · 11 comments
Closed

oneTime binding behavior breaking in a changing collection #301

blkbltjns opened this issue Jan 21, 2016 · 11 comments
Assignees
Labels

Comments

@blkbltjns
Copy link

This is not working as expected, the screen should show:
4 4
5 5
after clicking the button.

welcome.html

<template>
    <button click.trigger="clickme()">Click me!</button>
    <div repeat.for="item of items">${item.prop1 & oneTime} ${item.prop2 & oneTime}</div>
</template>

welcome.js

export class Welcome {
    items = [{prop1:1,prop2:1},{prop1:2,prop2:2},{prop1:3,prop2:3}];

    clickme() {
        this.items = [{prop1:4,prop2:4},{prop1:5,prop2:5}];
    }
}
@EisenbergEffect
Copy link
Contributor

What does it show instead?

@blkbltjns
Copy link
Author

It shows:
1 1
2 2

@gheoan
Copy link
Contributor

gheoan commented Jan 21, 2016

I think the excepted behaviour with one-time is
1 1
2 2

@blkbltjns
Copy link
Author

I don't understand this logic. I want a list of divs with each div binding oneTime to it's underlying viewmodel property. If I replace the list of data, there should be brand new divs (along with brand new viewmodels as it is a new list)...the oneTime should only apply to that specific view/viewmodel/property, not to the index in the list. Every other databinding framework I have used works the way I am talking about with a oneTime binding.

Otherwise, you could never use a oneTime binding to, for example, a text value inside a list in your application if that list could ever be changed, for example by sorting or filtering. If the individual item properties change, then sure, one-time binding shouldn't be expected to work, but that isn't what I'm talking about.

@gheoan
Copy link
Contributor

gheoan commented Jan 21, 2016

http://aurelia.io/docs.html#/aurelia/framework/latest/doc/article/cheat-sheet/5 explains the 3 types of binding in Aurelia. What you want is probably one-way

@blkbltjns
Copy link
Author

One-way gets dirty checked and removes a bunch of optimizations that one-time gets. One-time usually means the property you are binding to is immutable, which is the case I am talking about.

@blkbltjns
Copy link
Author

And just to show I'm not crazy, this does work:

<template>
    <button click.trigger="clickme()">Click me!</button>
    <div repeat.for="item of items">${item.prop1 & oneTime}</div>
</template>

This shows:
4
5

It just doesn't work if the div contains more than one one-time binding in the string template

@EisenbergEffect
Copy link
Contributor

I think it's a legitimate bug. @jdanyow @martingust Can you guys look into this?

@jdanyow jdanyow self-assigned this Jan 27, 2016
@jdanyow jdanyow added the bug label Jan 27, 2016
@blkbltjns
Copy link
Author

Just checking to see if this is still being worked on...?

@EisenbergEffect
Copy link
Contributor

@jdanyow Can you look at this?

@jdanyow
Copy link
Contributor

jdanyow commented Feb 10, 2016

sorry guys- I assigned this to myself and then forgot all about it. It seems to be specific to interpolation bindings, this template works as expected:

<template>
  <button click.trigger="clickme()">Click me!</button>
  <div repeat.for="item of items">
    <span textcontent.one-time="item.prop1"></span>
    <span textcontent.one-time="item.prop2"></span>
  </div>
</template>

will get a fix in shortly.

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

4 participants