Closed samuelsimoes closed 8 years ago
We can extend this behavior to subsets too.
And we can also infer the add
and remove
events automatically when we find this.where
on some computer function. My main concern with this will be the nested stores feature, nested stores won't be caught by the patterns described above.
I really prefer to be explicit because this can break in all sort of things, i.e.:
canAddTodos () {
const data = this.data;
// alias
return data.foo && data.bar;
}
canAddTodos () {
// different context (i.e.: this on the function is about the SomeService)
return SomeService.call(function () { return this.data.foo });
}
Although we can improve the current API to something like:
fullName (firstName, lastName) {
return `${firstName} ${lastName}`;
}
In that case the dependent attributes would be explicit at the method definition.
On the second example, I need to declare change:firstName
and change:lastName
events? Or Fluxo will read the arguments and infer the dependent events?
They would be inferred.
Since these compute functions does never receive any argument, we could use the argument names to infer what is needed to the compute.
Great. I liked. :ok_hand: Can I Implement this?
"Go get 'em, Tiger."
Do you know some safe way to get the function arguments? Thus far I only know the regexp /\([\w|\s|,]+\)/
on the function's string, but it's fragile. :pensive:
var foo = function (bar) {};
foo.arguments; // => undefined
Apparently there is no native reflection for functions, only regexps: http://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically-from-javascript
We could make some kind of transpiler (babel transpiler) but it doesn't worth at all.
Honestly, I don't think it's worth the complexity, too little benefit to too much complexity, explicit is always better than implicit (zen of python).
Alright, I also agree that It doesn't worth the complexity. Closing...
I was thinking that computed properties could have some sort of magic that dependent attributes would be read from the computer function's text body.
Example: you have a computed property about if you can add a ToDo, the
canAddTodos
property, that depends onthis.data.todosCount
, like this:Reading the method body string we could infer that this computed property relies upon the
todosCount
store property, so we can cut the necessity to user declares thechange:todosCount
event to compute the value, speeding up the things.What do you think?