Closed bmomberger-bitovi closed 6 years ago
We can drop the model “polyfill”
There may be a problem using canReflect.isBound(obj)
( issue )and related APIs for replacing the old can-connect/map
behavior that integrates with can-connect/constructor/store
.
In short, we were storing instances whenever they were bound to, not when they ran through the getList|get|create|update|destroy
methods. For example:
Todo.get({id:1}).then(function(todo){
setTimeout(() => {
todo.on("name", handler) //-> put in store
},10);
})
Instances without id
s would be put in the newInstanceStore
:
todo = new Todo();
todo.on("something", ...)
I see three courses of action:
can-reflect
or something similar be a global (and stateful) way of knowing this informationWe could support something like:
canReflect.onBindChange(function(obj, isBound){
if(obj === connection.Map && isBound) { PUT_IN_STORE(obj) }
})
Every observable would know to call this onBindChange
method when its bound
status changes.
canReflect.onBindChange(Type, handler(obj, isBound) )
Support .onBindChange
on the individual types:
Todo = DefineMap.extend({ .. })
canReflect.onBindChange( Todo, function(todo, isBound) {} );
Pros:
Cons:
If we do observe()
, we don't have a Type
to listen to. Perhaps we decorate Object
and Array
so something like the following is possible:
canReflect.onBindChange( Object, function(todoObj, isBound) {} );
POJO
objects with can-connect
, we probably need to Type them with something on their proto chain. This is so we could distinguish between something retrieved by can-connect
and a real POJO
.
class Todo() {
// does `observe(this)` automatically setup `Todo` for dispatching `.onBindChange`?
constructor(){ observe(this) }
}
Mammal
inherits from Animal
, does binding on a Mammal
fire a Animal.onBindChange
?We could release 4.0 working the old way, with only DefineMap and Map. Then we could figure out the right way of making it work later and try to squeeze in 4.0.
We could only "notice" bound elements if they bind immediately upon receiving an instance.
I don't think this will work as there's lots of behavior that can prevent immediate binding.
https://github.com/canjs/can-connect/issues/296 - storing instances
these things have been completed for 4.0 and remaining ones for 5.0
Last WIP for can-connect 2.0 (part of CanJS 4.0) is on https://github.com/canjs/can-connect/tree/major . The primary difficulties in getting any behaviors to work correctly with 4.0-release libraries are below:
.compute
function that returns a can-compute. One goal of this upgrade is removing all reference to can-compute, so this has to be rewritten or removed.