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

'unload' handler is not called #91

Closed
jjagoda opened this issue Oct 30, 2015 · 5 comments
Closed

'unload' handler is not called #91

jjagoda opened this issue Oct 30, 2015 · 5 comments

Comments

@jjagoda
Copy link

jjagoda commented Oct 30, 2015

I'm trying to subscribe to 'unload' event of modules initialized on selected DOM nodes.
My implementation is based on example shown here: http://conditionerjs.com/docs/#conditioner-sync

    // Find period element on the page
    var periodElement = document.querySelector('.peroid');

    // Initialize all datepicker modules
    // within the period element
    var datePickerNodes = conditioner.parse(periodElement);

    // Synchronize load events, we only want to work
    // with these modules if they are all loaded
    var syncGroup = conditioner.sync(datePickerNodes);

    // Wait for load event to fire
    Observer.subscribe(syncGroup,'load',function(nodes){

        // All modules now loaded

    });

    // Also listen for unload event
    Observer.subscribe(syncGroup,'unload',function(nodes){

        // One of the modules has unloaded

    });

The effects are:

  • when modules load the 'load' event if fired and the handler is called - this works fine
  • when modules unload the handler for 'unload' does not fire - this isn't working as it should

The call stack is briefly as follows:

  1. 'unload' event is fired - ModuleController's _unload publishes 'unload' event
  2. Observer.publish goes to line that executes matched callbacks (matches[i].fn(data);)
  3. goes into one of the callbacs which is NodeController._onModuleUnload (this empties the receivers array from Observer.publish)
  4. goes back to Observer.publish
  5. receivers are now empty so it doesn't go into the for loop (which would publish 'unload')

If I remove the line with Observer.conceal(moduleController,this); from NodeController's _onModuleUnload handler the 'unload' handler is working fine.

If you compare _onModuleUnload with _onModuleLoad then you'll see that Observe.conceal isn't called in the onload handler. What's the purpose of calling it in _onModuleUnload?

@rikschennink
Copy link
Owner

Thanks for the detailed report, I'm going to test it as soon as possible.

@rikschennink
Copy link
Owner

I've updated the tests (they failed to reproduce this problem in the first place) and fixed the _onModuleUnload method. This branch should solve the issue:
https://github.com/rikschennink/conditioner/tree/fix/syncgroup-unload

@jjagoda
Copy link
Author

jjagoda commented Nov 18, 2015

Rik, thanks for the fix.
These are my first days with conditioner so I couldn't help more then describing what actually happens.

I'll check the fix soon.

@rikschennink
Copy link
Owner

You're welcome :)

@rikschennink
Copy link
Owner

Merged in version 1.2.2
https://github.com/rikschennink/conditioner/tree/1.2.2

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