Update - piecesjs v0.1.0 (emit() and collaboration)
quentinhocde
I currently working with piecesjs on a web project, so I decided to make a refactoring
and officially create a release 0.1.0
Link to the repo : https://github.com/piecesjs/piecesjs
Major updates
- new
this.emit()
to trigger custom events. this.addEvent()
->this.on()
.this.removeEvent()
->this.off()
.- New beautiful comments.
- Clean up and update the readme.
- Add a collaboration section in the readme to explain how to build piecesjs locally.
this.emit() and custom events
Now you can emit a custom event with this.emit()
/**
* Emit a custom event
* @param { String } eventName
* @param { HTMLElement } el, by default the event is emit on document
* @param { Object } params
*/
this.emit('buttonIsMounted', document, { value: 'A Button is mounted!' });
Then, in a Piece you can use this.on()
, like the default events.
mount() {
this.on('buttonIsMounted', document, this.customEventTrigger);
}
// You can get parameters with event.detail
customEventTrigger(event) {
console.log(event.detail); // { value: 'A Button is mounted! }
}
unmount() {
this.off('buttonIsMounted', document, this.customEventTrigger);
}
New collaboration section in the readme
I add this new section to explain how to build piecesjs locally to open the project if someone is interested to make a pull request 👀
Clone the repo and at the root /
npm i
Link your local piecesjs to use it as an npm package
npm link piecesjs
Build piecesjs
npm run build
Test environment : in the folder /test
npm i
npm run dev
Enjoy and feel free to create a pull request!