Is the design pattern a chain of observers?
It seems like if no one is observing it, then it acts just like a plain function?
vs
Comparing the two cases above, one is
var fullName = can.compute(function () { ... });
and the other is
var fullName = function () { ... };
and do they behave just the same?
The only difference is when we in turn observe fullName.
so it looks like fullName is now observing person, and the anonymous function is in turn observing fullName?
So simply put, can we say that
can.compute(function() { ... }) returns a function bar that, if the function bar is not observed, then it is just the same as just a plain function.
But if the returned function bar is observed, then this function will in turn observe any observable objects that the function need to use to compute the value?
Is that the interface and behavior of can.compute(), when
can.compute(function() { ... }) is used?
It seems we can set up the observer chain further: to have shippingLabel observe fullName, and let shippingLabel be observed by yet another function:
We can also see that we can change the underlaying data any way we want, but if the function "computes" and get the same value, then the change observer is not invoked:
I know user of can.compute() is not supposed to know about the implementation details of can.compute(), but to understand what is going on, and what can work in this “chain of observers”, is it true that when we get a function foo from can.compute(bar), then whenever we bind a change observer on foo, then the observer system will trigger a flag to see “what I am going to be looking at next”, and then the system will invoke bar(), and the system will see what observed objects is looked at, say it is wah and lah (when wah.attr("prop1") and lah.attr("prop2") are invoked), and under the hood, the system will make foo observe both wah and lah? And now the system will set the flag back to normal and let everything work as normal again.