Open andrejewski opened 7 years ago
See can-dom-mutate
for the API and implementation.
The API is:
can-dom-mutate
dispatchNodeInsertion( node [, callback ])
dispatchNodeRemoval( node [, callback ])
dispatchNodeAttributeChange( node, attributeName, oldValue [, callback ])
onNodeInsertion( node, callback )
onNodeRemoval( node, callback )
onNodeAttributeChange( node, callback )
onInsertion( callback )
onRemoval( callback )
onAttributeChange ( callback )
Note: the optional callback to the dispatch methods are called right after the mutation is actually broadcast (all mutations are batched). This eliminates the need for a hack like afterMutation()
in our tests.
Note: all the listener events return remove
functions which unbind the listener.
can-dom-mutate/observer
get() observer
getGlobalDefault([ global ]) observer
set( observer )
onChange( callback )
This API provides everything a can-global
package would provide, but this is only for the one shared MutationObserver.
can-dom-mutate/node
autoConfigure()
: automatically optimizes for the current MutationObserver (leverages observer.onChange
)appendChild(), insertBefore(), removeChild(), replaceChild(), setAttribute()
methodscan-dom-mutate/events/{attributes|inserted|removed}
These are can-dom-events
events; they did make sense to include in can-dom-mutate
as they all can be derived from a single make-mutation-event
generator.
I'd like to break out
can-util/dom/mutate
andcan-util/dom/mutation-observer
into their own packagecan-dom-mutate
which will provide:dom/mutate
's current DOM Node API (intercepted[verb]Child()
calls)dom/attr
needs this too)attributes
,inserted
, andremoved
custom eventsBy "depending on concerns" I mean to decide if logically these events do in fact belong inside the package instead of their own. Moving forward with implementation, this will become more clear.
As far as structure goes, I'm currently thinking:
can-dom-mutate
for replacingdom/mutation-observer
can-dom-mutate/node
for replacing thedom/mutate
APIcan-dom-mutate/synthetic
for the low-level APIcan-dom-mutate/events/{attributes,inserted,removed}
for the custom eventsDiscussion is welcome and I'm happy to address concerns regarding my grand vision.