Open benmgreene opened 9 years ago
@benmgreene the issue should be fixed if we find a way to stop tracker. I guess the tracker.autorun should return some handle/function to stop tracking. This handle could be associated with typeahead instance and invoked on typeahead destroy
event. Please feel free to send PR.
@benmgreene I din't find easy way to stop computation (run by meteor tracker) on destroying typeahead instance. Current idea is to replace $.fn.typeahead to intercept only typeahead('destroy') calls to invoke custom dispose function. Is it acceptable solution? It would be great if typeahead has support of destroy
event. Now I can patch the typeahead.bundle.js to raise this event.
@sergeyt thanks for your suggestions. I spent some time hacking on a solution -- see:
https://github.com/benmgreene/meteor-typeahead/commit/aabe1e8838f6d0ebb2c032c9f76404d9965beda8
This code works, but the problem is in getting it called. If I call Meteor.typeahead.destroy()
from the template's destroy
(or now onDestroyed
) callback, it's already too late -- the autorun
's computation has already been invalidated.
The alternative is to call Meteor.typeahead.destroy()
in a different template's event. Currently this won't work because Meteor.typeahead.destroy
, similarly to Meteor.typeahead.inject
, limits the selector lookup to the current Template.instance()
if there is one. It's easy enough to provide a bypass from that, but it'd be much cleaner to find a way to call it from the template's destroy
/onDestroyed
callback. Perhaps there's a way to defer the autorun
?
Any thoughts?
I went ahead and added the bypass, and it works, but it's definitely not ideal.
@benmgreene I think you are on right track. The solution looks good to me. Please go ahead to send PR.
When logging out, I get the following typeahead errors:
I've tried explicitly destroying the typeahead beforehand, using
$(".typeahead").typeahead("destroy")
, but it doesn't help. I assume the problem is due to the underlying collection disappearing from minimongo and that change reactivity effecting, and breaking, typeahead.Seen this? Any thoughts? Thanks much.