Closed mvaullerin closed 9 years ago
What's the use-case for this? As apposed to either setting the default namespace at the config stage or using the namespace()
setter
First, sorry if it's not really understandable, as French my English is obviously pretty bad :)
I develop a plateform for events, and I need the namespace to be the ID of the event for all the angular app (because someone can be connected to the plateform for two events in the same time). And I set the namespace after checking the ID correspond to a valid event.
If I don't have this method, I have to use the namespace() setter dans specify the namespace all the time. (or I missed something)
Any reason you can't set it in the config stage? e.g.
.config(['lockerProvider', function config(lockerProvider) {
lockerProvider.defaults({
namespace: 'myApp',
});
}]);
The ID is dynamic, I get it in a controller.
Ok, I see what you mean. I would implement something a little different than this PR to achieve this though.
I'm thinking maybe a second parameter to the namespace and driver methods, to set the value on the same instance.
This is just a convenience though, since you could, as you say, always use the namespace setter each time you call a method.
Having said that, I would suggest that you wrap this in your own service if you haven't already. e.g.
.factory('Store', function (locker) {
var namespace = 'default';
return {
setNamespace: function (ns) {
namespace = ns;
return this;
},
get: function (key, def) {
return locker.namespace(namespace).get(key, def);
},
put: function (key, val, def) {
return locker.namespace(namespace).put(key, val, def);
},
// etc
};
});
// then in your controller
Store.setNamespace('foo');
Store.get('bar');
Or not :) but you get the idea
Good idea, I will try this. Thanks :) And thanks for this module, it's really awesome :)
Allow user to change the namespace globally.