canjs / can-connect

Model layer utilities for every JavaScript framework! Assemble real-time, high performance, restful data connections.
https://canjs.com/doc/can-connect.html
MIT License
29 stars 16 forks source link

Items that need to be tackled for 2.0 release #368

Closed bmomberger-bitovi closed 6 years ago

bmomberger-bitovi commented 6 years ago

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:

justinbmeyer commented 6 years ago

We can drop the model “polyfill”

justinbmeyer commented 6 years ago

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 ids would be put in the newInstanceStore:

todo = new Todo();

todo.on("something", ...)

I see three courses of action:

make can-reflect or something similar be a global (and stateful) way of knowing this information

We 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:

Do nothing for 4.0, figure it out after

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.

Only add to the store while going through can-connect instance methods

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.

Related:

https://github.com/canjs/can-connect/issues/296 - storing instances

justinbmeyer commented 6 years ago

these things have been completed for 4.0 and remaining ones for 5.0