Stache #each teardown throws an error on observable functions #2001

Closed
dylanrtt opened this Issue Oct 19, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@dylanrtt
Contributor

dylanrtt commented Oct 19, 2015

I don't know if this was an intentional feature, but you used to be able to do #each on a viewmodel's observable prototype function. For example:

// viewmodel
var VM = can.Map.extend({
  myList: function() {
    return this.attr('myOtherList');
  }
});

// stache
{{#each myList}} ...

http://jsbin.com/leladosese/edit?html,js,console,output

You still can, but the teardown throws an error on live.js#L442 because the function (not a compute) doesn't have an unbind method. This error did not occur in pre.8 and is now showing up since I updated to beta.6.

Strangely, it works fine if there is no element wrapping the #each in that example.

I don't personally care about this feature because I was able to just move it to a virtual property where it I think it belongs, but now you know in case you want to continue to support it.

@justinbmeyer justinbmeyer added the bug label Oct 19, 2015

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Oct 19, 2015

Contributor

Looks like a bug. I'll take a look in 20 min. Thanks!

Contributor

justinbmeyer commented Oct 19, 2015

Looks like a bug. I'll take a look in 20 min. Thanks!

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Oct 19, 2015

Contributor

So, it seems like the problem is calling .empty() right? This issue makes it sound like you can't do #each. You can do #each, just the tearing down isn't working right?

Contributor

justinbmeyer commented Oct 19, 2015

So, it seems like the problem is calling .empty() right? This issue makes it sound like you can't do #each. You can do #each, just the tearing down isn't working right?

@dylanrtt

This comment has been minimized.

Show comment
Hide comment
@dylanrtt

dylanrtt Oct 19, 2015

Contributor

Yes, that's correct. Sorry for not clarifying.

I worded it that way because you can't/won't use #each if the teardown is broken and I wasn't sure if it was an intentional feature.

Contributor

dylanrtt commented Oct 19, 2015

Yes, that's correct. Sorry for not clarifying.

I worded it that way because you can't/won't use #each if the teardown is broken and I wasn't sure if it was an intentional feature.

@dylanrtt dylanrtt changed the title from Can no longer #each on an observable prototype function to Stache #each teardown throws an error on observable functions Oct 19, 2015

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Oct 19, 2015

Contributor

So there is something I would like to get rid of, but can't until 3.0.

Basically, the current behavior is to call functions if they are on a can.Map, but not to call functions if they are not.

Fortunately, call expressions clean this up by always calling functions.

In 3.0, we will probably clean this up, or make helper expressions adopt call expression behavior entirely.

For now, I'm going to add a special flag to can.compute.read that HelperScopeLookup expressions will use to say "give me the function, unless it's on a can.Map. If it is on a can.Map, call the function and give a compute".

Contributor

justinbmeyer commented Oct 19, 2015

So there is something I would like to get rid of, but can't until 3.0.

Basically, the current behavior is to call functions if they are on a can.Map, but not to call functions if they are not.

Fortunately, call expressions clean this up by always calling functions.

In 3.0, we will probably clean this up, or make helper expressions adopt call expression behavior entirely.

For now, I'm going to add a special flag to can.compute.read that HelperScopeLookup expressions will use to say "give me the function, unless it's on a can.Map. If it is on a can.Map, call the function and give a compute".

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