Skip to content

Bind on load (DOMContentLoaded) #571

@fieg

Description

@fieg

Description
Current version of IAS binds as soon as the javascript is executed. This complicates listening for events that start on bind, because attaching listeners happen after the event is already dispatched (see example below). Some events that are impacted by this: prefill, next, binded and probably more.

bind is NOT impacted at the moment because is has a special case to trigger it after the fact, which you can see here:

if (event === Events.BINDED && this.binded) {
callback.bind(this)();
}

Example
Take this example:

1  let ias = new InfiniteAjaxScroll('.blocks', {
2       item: '.blocks__block',
3       next: '.pager__next',
4       trigger: '.trigger',
5       prefill: true,
6 });
7
8 ias.on('prefill', function() { /* do something */ });

Here we are listening for the prefill event, but because the javascript is exectured right away, when the line 8 is executed the prefill event is already dispatched. So attaching the listener is happening after the fact.

Alternatives

An alternative solution would be to allow registration of listeners through an option. For example:

1  let ias = new InfiniteAjaxScroll('.blocks', {
2       item: '.blocks__block',
3       next: '.pager__next',
4       trigger: '.trigger',
5       prefill: true,
6       listeners: {
7          prefill: function() { /* do something */ },
8       }
9 });

Another alternative would be to handle it in as similar way as the bind event. But I think that would cause more problems then that it solves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions