Small(ish) listener implementation for Sanity. Useful if you only need listeners.
- Node.js >= 6
- Modern(ish) browsers (IE >= 11, Chrome, Safari, Firefox etc)
npm install --save dumbo-ears
const DumboEars = require('dumbo-ears')
// Instantiate a client
const client = new DumboEars({
projectId: 'myProjectId',
dataset: 'myDataset',
token: 'moop', // optional
})
// Listen for changes on the given query
const subscription = client
.listen(
'*[_type == $someType]',
{someType: 'article'},
{includePreviousRevision: false}
)
.subscribe(mutation => console.log(mutation))
// Unsubscribe from events after 30 seconds
setTimeout(() => {
subscription.unsubscribe()
}, 30 * 1000)
You can load this module as a UMD-bundle from unpkg - https://unpkg.com/dumbo-ears
If used in a global browser context, it will be available as window.DumboEars
MIT © Espen Hovlandsdal