-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can.route crossbind to can.Map #752
Comments
We probably want the ability to do generic serializer/deserializer functions instead of just a property name map, for when your state is something like As a note on serializer functions, |
Other things to consider: Passing a Map constructor functionAppState = can.Map.extend({ ... })
can.route.data(AppState) Passing can.route an object of prototype properties
Serializing and de-serializingAppState = can.Map.extend({
setSearchTerm: function(newTerm){
return newTerm || ""
},
setFlags: function(newValue){
return typeof newValue === "string" ? newValue.split("") : newValue || [] )
},
serialize: function(){
var s = this.attr();
s.flags = s.flags.join("");
return s;
}
}) |
I assume you mean if I do something like: AppState = can.Map.extend({
doSomething: function(){ ... }
})
can.route.data(AppState); You want someone to be able to write:
? Imo, Modules should not call can.route directly, they should instead be passed an observable and listen / make changes to it. That means,
|
As stated above, serialize and de-serialize are handled with setters (or the new can/map/define) and the serialize method on the can.Map instance. So creating an appState and binding it should involve: a) define a can.Map constructor, with added serialize helpers (used to convert this object into a can.route params string) and deserialize helpers (used to convert the other direction) Here's a proposed API for binding some can.Map state object as can.route.data. I'm not sure about the name, a few options are:
can.route.Map@function can.route.Map Assign a can.Map instance that acts as can.route's internal can.Map. The purpose for this is to cross-bind a top level state object (Application State) to the can.route. @Signature @param {can.Map} mapConstructor A can.Map constructor function. A new can.Map instance will be created and used as the can.Map internal to can.route. @Signature @param {can.Map} mapInstance A can.Map instance, used as the can.Map internal to can.route. @Signature @param {function(attrs)} func A method, which will be called after can.route.ready is called. It will be passed attrs, an object representing the deparameterized URL. This function should create and return a can.Map instance, which will be used as the internal can.Map for can.route. Use
Loading data on application startA common use case is loading some metadata related to the Application State when the application begins, which must be loaded as part of the Application State before we can start up all the components. To implement this functionality, load this data, call the AppState constructor with the data and save it in the init method, then call can.route.Map and can.route.ready to set the application init process in motion. For example:
|
Map would break convention as we only call those functions with new. Sent from my iPhone
|
Ok, then can.route.scope is probably the next best option, since it has all the same signatures: map instance, map constructor, function. We want this to be a function though, whereas component's scope is a property.
Agree? |
Decided on can.route.map. I'll work on adding this and getting some docs in shortly. |
A common pattern in our apps is binding a can.Map object (representing application state) to the can.route, and vice versa. We need a cleaner API for this. Often the code looks like:
But with additional logic accounting for ev.batchNum being unique.
This issue proposes an API like:
can.route.data( appState )
We'll possibly need options for that method to map appState properties to what they'll be called in can.route.
The text was updated successfully, but these errors were encountered: