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

Adding a context with same name not empty after being removed before #25

Open
philjones88 opened this issue Aug 20, 2015 · 1 comment
Open

Comments

@philjones88
Copy link

Hi,

Given the scenario:

// Make a fresh context
genie.addContext('foo');

// Add a wish
genie({ magicWords: 'foo 1', context: 'foo', action: function () { alert('foo 1'); } });

// Remove the context, this deletes the context and wish, right?
genie.removeContext('foo');

// Add Context again with same name
genie.addContext('foo');

// Check contents of "new" context
genie.getWishesInContext('foo');

The "new" context after removing it has the item already in it.

I was expecting the second time creating a context of the same name for it to be empty.

The general scenario is using Angular UI routing's onEnter and onExit as I want to build a context for the page and add wishes to that context, based on resolved API data, but, remove that context when the user leaves the page.

I did investigate using the directive but I had similar issues of it not being removed from context when the page is destroyed.

I want to keep my "main" contexts clean of items on the specific page as this is a large system so technically the items cached could have been deleted by other people.

Any ideas?

@philjones88 philjones88 changed the title Adding a context with same not empty after being removed before Adding a context with same name not empty after being removed before Aug 20, 2015
@kentcdodds
Copy link
Owner

I'll be honest, it's been awhile since I've used this library (but you're starting to light the fire for me to start working on it again). Removing the context a wish belongs to will not remove the wish (see the code).

If you want to do that, you could first call genie.deregisterWishesWithContext('foo').

Also, you might consider using Path Contexts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants