Skip to content
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

Unbind unexpected behavior #71

Open
martinbrylski opened this issue Jul 6, 2015 · 1 comment
Open

Unbind unexpected behavior #71

martinbrylski opened this issue Jul 6, 2015 · 1 comment
Labels
Milestone

Comments

@martinbrylski
Copy link

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);
      };
@scotttrinh
Copy link
Owner

To preserve backwards compatibility, I will keep the current behavior of unbind, but we can pass another argument to the method that will decide whether to remove the value from the DB or not. Does that sound reasonable to you, @martinbrylski or anyone else who might want this behavior changed?

@scotttrinh scotttrinh added this to the 1.3.0 milestone Jun 19, 2016
@scotttrinh scotttrinh modified the milestones: 1.3.0, 1.4.0 Jul 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants