Closed jeme closed 11 years ago
Final design: (example taken from numeric converter)
.convert('num', () => {
return {
parse: (param) => {
var accepts = !isNaN(param);
return {
accept: accepts,
value: accepts ? Number(param) : 0
};
},
format: (value) => {
if (isNaN(value))
throw new Error("Value was not acceptable for a numeric parameter.");
return value.toString();
}
};
});
When interpolating routes, either through a
$state.goto
call for a state associated with a route, or directly with$route.change
, the converters registered in the route should be used to convert reversely.This is to enable the developer to write more elaborate converters that convert a simple string into an object, that object should be able to be converted back.
(It is not a recommendation that developers choose to do that, but since they are able to we have to provide the reverse as well)
Example of a converter today:
Example of a converter in the future?: