-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Dependency Observables fail in Collections #32
Comments
Hi, Yeah. This is actually expected. The reason is var App = blocks.Application();
var Cake = App.Model({
cakeType: blocks.observable(),
cakeSize: blocks.observable(),
init: function () {
this.fullCake = blocks.observable(function() {
return this.cakeType() + 'cake (' + this.cakeSize() + ')';
}, this);
}
})
var Cakes = App.Collection(Cake);
App.View('Bakery', {
cakes: Cakes([
{ cakeType: 'strawberry', cakeSize: 'small' },
{ cakeType: 'chocolate', cakeSize: 'large' }
])
}); Additionally, I will leave this issue open to think about if there could be a way to fix the problem. |
Hi Thanks for the prompt reply! As for solving the problem, I haven't really looked into jsblocks any deeper but spontaneously, I'd say it could be nice having a self-reference in dependency observables that can access the instance data. I'm thinking about not cloning the function prototype but internally passing it a For anyone interested, another solution I just figured that I personally like more (at least code-style wise) is using the following code: var Cake = App.Model({
cakeType: blocks.observable(),
cakeSize: blocks.observable(),
fullCake: function(self) {
return self.cakeType() + 'cake (' + self.cakeSize() + ')';
},
});
|
Hmm. Yes. This is interesting idea. I really like how you approached the problem. I will think about it and update you on the status. Thanks. |
I have fixed the problem. Now you can use the code from your first post and it will work how it is expected. |
So, I'm not sure if this is actually a problem or if I've missed an important detail here, but I can't seem to find a way to solve it. I created a model following the example of dependency observables and model introduction and it worked just fine.
However, if I do that and push multiple of these models into a collection, the observable is not evaluated correctly anymore.
I'm using the following code:
You would expect this to display
Let's eat some, strawberrycake (small)
andLet's eat some, chocolatecake (large)
. However, while the input values are displayed correctly, the dependency obsevable returnsLet's eat some, strawberrycake (small)
in both entries.I haven't found a solution for this yet, the error also occurs using
{{this.fullCake}}
or{{$this.fullCake}}
The text was updated successfully, but these errors were encountered: