@@ -284,6 +284,9 @@ const EventHandler = struct {
284284
285285 const muevt = parser .eventToMutationEvent (evt .? );
286286
287+ // TODO get the allocator by another way?
288+ const alloc = data .cbk .nat_ctx .alloc ;
289+
287290 if (std .mem .eql (u8 , t , "DOMAttrModified" )) {
288291 mrs .first = .{
289292 .type = "attributes" ,
@@ -305,12 +308,41 @@ const EventHandler = struct {
305308 if (o .options .characterDataOldValue ) {
306309 mrs .first .? .oldValue = parser .mutationEventPrevValue (muevt ) catch null ;
307310 }
311+ } else if (std .mem .eql (u8 , t , "DOMNodeInserted" )) {
312+ mrs .first = .{
313+ .type = "childList" ,
314+ .target = o .node ,
315+ .addedNodes = NodeList .init (),
316+ .removedNodes = NodeList .init (),
317+ };
318+
319+ const rn = parser .mutationEventRelatedNode (muevt ) catch null ;
320+ if (rn ) | n | {
321+ mrs .first .? .addedNodes .append (alloc , n ) catch | e | {
322+ log .err ("mutation event handler error: {any}" , .{e });
323+ return ;
324+ };
325+ }
326+ } else if (std .mem .eql (u8 , t , "DOMNodeRemoved" )) {
327+ mrs .first = .{
328+ .type = "childList" ,
329+ .target = o .node ,
330+ .addedNodes = NodeList .init (),
331+ .removedNodes = NodeList .init (),
332+ };
333+
334+ const rn = parser .mutationEventRelatedNode (muevt ) catch null ;
335+ if (rn ) | n | {
336+ mrs .first .? .removedNodes .append (alloc , n ) catch | e | {
337+ log .err ("mutation event handler error: {any}" , .{e });
338+ return ;
339+ };
340+ }
308341 } else {
309342 return ;
310343 }
311344
312- // TODO get the allocator by another way?
313- var res = CallbackResult .init (data .cbk .nat_ctx .alloc );
345+ var res = CallbackResult .init (alloc );
314346 defer res .deinit ();
315347
316348 // TODO pass MutationRecords and MutationObserver
0 commit comments