ApoorvSaxena / ApoorvSaxena/lozad.js
Extending `load` function instead of overriding
- Ngôn ngữ chính
- JavaScript
- Star
- 7.5k
- Fork
- 435
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## Expected Behavior
I would like to extend `load` function not to override it, e.g. add dispatching some event, add some logs etc.
## Current Behavior
I can provide my own `load` function which override the default one. So if I write something like this:
```js
lozad('.lozad', {
load: function(el) {
console.log('loading element');
}
});
```
lazy loading will not work, because my function (with only `console.log`) will override the default one.
## Possible Solution
Export `load` function from `defaultConfig`, so I can do this:
```js
// lozad.js
export function load() {
...
}
export default function lozad() {
...
}
```
```js
// my-code.js
import lozad, { load } from 'lozad';
lozad('.lozad', {
load: function(el) {
console.log('loading element');
// dispatch my event
// do something
load();
}
});
```
## Context
I want to replace [`lazysizes`](https://github.com/aFarkas/lazysizes) with [`lozad`](https://github.com/ApoorvSaxena/lozad.js), but I need to dispatch [`lazybeforeunveil`](https://github.com/aFarkas/lazysizes#js-api---events) event.
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.