From 5a4e3564140b1c106ad93ac0833d5892e42512b5 Mon Sep 17 00:00:00 2001 From: Andres Morey Date: Mon, 18 Sep 2017 07:56:51 +0000 Subject: [PATCH] updated README --- README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41e2d40..7335538 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,26 @@ SentinelJS is a tiny JS library that lets you detect new DOM nodes using CSS sel ## Introduction -SentinelJS is a tiny JS library that makes it easier to set up watch functions that will notify you anytime a new DOM node is added that satisfies a CSS selector rule. +SentinelJS is a tiny JS library that makes it easy to set up watch functions that will notify you anytime a new DOM node is added that satisfies a CSS selector rule. SentinelJS is useful for writing plugins that make modifications when a new DOM node is inserted. This can be useful for creating Shadow DOM-like experience where you can define interactive components using purely HTML. + +The latest version of SentinelJS can be found in the `dist/` directory in this repository: + * [sentinel.js](https://raw.githubusercontent.com/muicss/sentineljs/master/dist/sentinel.js) + * [sentinel.min.js](https://raw.githubusercontent.com/muicss/sentineljs/master/dist/sentinel.min.js) + +You can also use it as a CJS or AMD module: + +```bash +$ npm install --save sentinel-js +``` + +```javascript +var sentinel = require('sentinel-js'); + +sentinel.on('my-awesome-component', function(el) { + // add more functionality to the element + el.innerHTML = 'The sentinel is always watching.'; +}); +``` ## Quickstart @@ -52,10 +71,22 @@ SentinelJS is a tiny JS library that makes it easier to set up watch functions t #### on(cssSelectors, callbackFn) +Use the `on()` method to set up a watch for new DOM nodes. + + * `cssSelectors` - A single selector string or an array + * `callbackFn` - The callback function + #### off(cssSelectors[, callbackFn]) +Use the `off()` method to remove a watch. If `callbackFn` is emtpy, all watches for the given cssSelector will be removed. + + * `cssSelectors` - A single selector string or an array + * `callbackFn` - The callback function you want to remove the watch for (optional) + #### reset() +The `reset()` method will remove all watches and callbacks from the sentinel library. + ### Async Loading To make it easy to use SentinelJS asynchronously, the library dispatches a `sentinel-load` event that will notify you when the library is ready to be used: