You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be useful to make it possible to handle all of the different behaviors using functions.
To do this, we would need to create a standard format for what these return. Creating the behavior functions would be handled by another package.
For example, here is what an async and a value might look like:
import{ObservableObject,asyncGet,resolver}from"can/everything";classAppViewModelextendsObservableObject{staticdefine={customerId: Number,// this uses an `asyncGet` function that creates a DefinitionObject type that has// specific Symbols that ObservableObject understandscustomer: asyncGet((resolve)=>{Customer.get({id: this.customerId}).then((customer)=>{resolve(customer);});}),name: String,// this uses a `resolver` function that creates a DefinitionObject type that has// specific Symbols that ObservableObject understandsnameChangeCount: resolver(({ listenTo, resolve })=>{letcount=0;listenTo("name",()=>resolve(++count));resolve(count);})};}
The benefits of this are:
users don't have to remember specific property names (like value, async, etc)
we could eliminate the multiple ways of handling the same thing (prop: Number vs prop: { type: Number }
if this is the only way of doing things, it would enable tree-shaking modules you aren't using (for example ResolverObservable adds 3.37 kB)
The downsides are:
we would have to figure out how you compose two behaviors, if we want that to be possible
I think it would be useful to make it possible to handle all of the different behaviors using functions.
To do this, we would need to create a standard format for what these return. Creating the behavior functions would be handled by another package.
For example, here is what an
async
and avalue
might look like:The benefits of this are:
value
,async
, etc)prop: Number
vsprop: { type: Number }
ResolverObservable
adds 3.37 kB)The downsides are:
Related to canjs/can-stache-element#47 (comment).
The text was updated successfully, but these errors were encountered: