Skip to content

An attempt at a more intuitive API wrapper around W3C DOM MutationObserver

License

Notifications You must be signed in to change notification settings

barneycarroll/muty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

muty

Build Status

The W3C DOM MutationObserver API is verbose and unintuitive. This wrapper makes DOM observation terse and obvious.

What?

Exposes:

<script src=//unpkg.com/muty/script.js></script>
<script src=//unpkg.com/muty/module.js type=module></script>
import muty from 'muty'
// or
var muty = require('muty')
// A single function for mutation observation
muty( options, element, callback ) // => MutationObserver

// An options object with all boolean flags set to true for broad capture
muty.options

Allowing:

// Blanket logging of all DOM mutations
muty( muty.options, document, function( records ){ console.log( records ) } )

// In application code, maybe something like this
var editor = document.querySelector( '[contenteditable]' )

muty(
  { characterData : true, subtree : true } ,
  editor,
  function( mutations, observer ){
    editor.classList.add( 'changed' )

    observer.disconnect()
  }
)

What not?

  • A MutationRecord processor, or any kind of higher-level abstraction. Use Mutation Summary instead.
  • A MutationObserver polyfill for non-supporting browsers. Use Mutation Watcher instead.
  • A perfect API:
    • Curry it if you want intermediary partially applied observers.
    • Use flyd (for Fantasy Land streams) or Bluebird (for Promises) if you have opinionated async data flow requirements.

About

An attempt at a more intuitive API wrapper around W3C DOM MutationObserver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published