Skip to content

Add instance and event manager

Jacob Schatz requested to merge js_instance_event_manager into master

Adds an event manager. Use the Page object to create a new page. You can then add classes you use as instances using use. You can add the events through the page and they will get added to the list of events for said page. When you call allOff() all events will be removed properly. When you call removeAll() all events and instances from that page will be removed. On page change we can call removeAll() for each page. cc @dzaporozhets @DouweM

Example usage:

In some sort of central dispatcher:

issuePage = GlPage.new('Issue')
# Then instantiate issue classes that the issue page uses
issuePage.use(new Issue(), 'issue')
issuePage.use(new Subscription(), 'subscription')

# If you need the instance back you can run
subscription = issuePage.get('subscription')

In any issue class:

issuePage = GlPage.get('Issue')
# Any jQuery event signature as usual
issuePage.on('.someBtn','click', -> console.log('works'))

You can then run this to remove all events tied to the issue page:

issuePage = GlPage.get('Issue')
issuePage.allOff()

You can run this to remove all events and all instances from the page:

issuePage.removeAll()

Fixes #14768 (closed)

Merge request reports