Created by @vasek in Q&As
@vasek
@vasek

Hi, I'm trying to implement custom service that will execute on every update of the page to reinitialize e.g. tooltips on page etc.

I wrote it according to https://github.com/nittro/nittro/wiki/Custom-services. The constructor gets called, but the update callback is never executed. The actual pages are loaded correctly via nittro, just my update callbacks are never called. I ran out of ideas - could you please point me somewhere, what to check, what might be wrong? Thanks.

This is my code now:

_context.invoke('App.Services', function (DOM) {

    var PageUpdateHelper = _context.extend(function (page) {

        this._ = {
            page: page
        };

        console.log('constuctor called'); // called ok
        console.log(page); // called ok
        this._.page.on('update', function () {
            console.log('direct function called'); // never called
        });
        this._.page.on('update', this._handleUpdate.bind(this));
    }, {
        _handleUpdate: function () {
            console.log('handle update called'); // never called
    });

    _context.register(PageUpdateHelper, 'PageUpdateHelper');

}, {DOM: 'Utils.DOM'});

And one more information - from the console.log(page) above, I can see that my callbacks are registered in _.eventEmitter.listeners.update.

@jahudka
@jahudka

Hi, you're right on track, you're just using the wrong event of the wrong service - the page service has no update event, it might've been there long ago in the pre-2.0 versions, but in current Nittro you need to inject snippetManager instead and listen for its after-update event :-) it will be called each time one or more snippets are updated by Nittro as well as upon the initial page load. Sorry about the misleading documentation, I'll fix it asap!

@vasek
@vasek

Hi, thanks a lot. It's working now with the snippetManager and after-update event ;)

@jahudka
@jahudka

no problem :-) glad it helped :-)

Sign in to post a reply