Open
Description
I've a scope variable that I'm watching at. Based on this variable I bind to a localForage key. In case of change, I want to unbind the 'old' value and bind the 'new'.
The current unbind method will delete the data stored for this key, what is not the intended behavior (the opposite of bind())
Either I'm wrong with my use-case and the usage of this library or unbind has a strange behavior.
To overcome my issue i currently I replaced the unbind method with:
LocalForageInstance.prototype.unbind = function unbind($scope, opts) {
if(angular.isString(opts)) {
opts = {
key: opts
}
} else if(!angular.isObject(opts) || angular.isUndefined(opts.key)) {
throw new Error("You must define a key to unbind");
}
var defaultOpts = {
scopeKey: opts.key,
name: defaultConfig.name
};
// If no defined options we use defaults otherwise extend defaults
opts = angular.extend({}, defaultOpts, opts);
var self = lfInstances[opts.name];
if(angular.isUndefined(self)) {
throw new Error("You must use the name of an existing instance");
}
// $parse(opts.scopeKey).assign($scope, null);
if(angular.isDefined(watchers[opts.key])) {
watchers[opts.key](); // unwatch
delete watchers[opts.key];
}
return $q.when(true);
};