An open API service indexing awesome lists of open source software.

https://github.com/mawrkus/champoo

🍻 Lazy loading pretty much everything!
https://github.com/mawrkus/champoo

lazy-loading lazyload lazyload-images

Last synced: about 2 months ago
JSON representation

🍻 Lazy loading pretty much everything!

Awesome Lists containing this project

README

        

# Champoo
[![npm](https://img.shields.io/npm/l/champoo.svg)](https://www.npmjs.org/package/champoo)

Champoo is a lazy loader library.
By separating conditioners & loaders, it gives you the flexibility to easily load pretty much everything, the *lazy way*... It is extensible & has a small footprint.

## Installation

### Node

```bash
yarn add champoo
```
or
```bash
npm install champoo
```

### Browser

The package is available as a UMD module: compatible with AMD, CommonJS and exposing a global variable `Champoo` in `lib/Champoo.js` (less than 1Kb minified and gzipped).

## Usage

```html



```

```js
import Champoo from '../es/Champoo';
import { UrlLoader } from '../es/loaders';
import { TimeoutConditioner, ViewportConditioner, MousePointerConditioner } from '../es/conditioners';

import FaceBookCommentsLoader from './FaceBookCommentsLoader';

const champoo = new Champoo({
conditioners: {
timeout: new TimeoutConditioner(),
viewport: new ViewportConditioner(),
pointer: new MousePointerConditioner()
},
loaders: {
'url': new UrlLoader(),
'fb-comments': new FaceBookCommentsLoader()
}
});

champoo.init().then((r) => {
console.log('All lazy elements loaded.', r);
});
```

## Demo

```bash
git clone https://github.com/mawrkus/champoo.git
cd champoo
npm install
npm run server:demo
```

## Custom conditioners creation

A conditioner is a simple class having the following interface:

```js
class AmazingConditioner {

/**
* @param {HtmlElement} element
* @param {Array} params The conditioner parameters declared on the HTML element
* @return {Promise}
*/
check({ element, params }) {
return new Promise((resolve, reject) => {
// call resolve() whenever the element meets the condition(s)
// call reject() if there's a problem
});
}

}
```

By registering it when instantiating Champoo...

```js
const champoo = new Champoo({
conditioners: {
amazing: new AmazingConditioner()
},
loaders: {
// ...
}
});
```

...you can use it in the HTML:

```html

```

## Custom loaders creation

A loader is a simple class having the following interface:

```js
class AmazingLoader {

/**
* @param {HtmlElement} element
* @param {Array} params The loader parameters declared on the HTML element
* @return {Promise}
*/
load({ element, params }) {
return new Promise((resolve, reject) => {
// call resolve() when the element has been loaded
// call reject() if there's an error while loading
});
}

}
```

By registering it when instantiating Champoo...

```js
const champoo = new Champoo({
conditioners: {
// ...
},
loaders: {
amazing: new AmazingLoader()
}
});
```

...you can use it in the HTML:

```html

```

## Contribute

1. Fork it: `git clone https://github.com/mawrkus/champoo.git`
2. Create your feature branch: `git checkout -b feature/my-new-feature`
3. Commit your changes: `git commit -am 'Added some feature'`
4. Check the build: `yarn run build`
4. Push to the branch: `git push origin feature/my-new-feature`
5. Submit a pull request :D