jfroelich / rss-reader

A simple Chrome extension for viewing RSS feeds
Other
10 stars 0 forks source link

Implement semantic-remove in dom-utils #726

Closed jfroelich closed 5 years ago

jfroelich commented 5 years ago

Replace remove-image with a more general purpose semantic-remove function. The function accepts an element as input, and removes the element from its containing document. The special remove image logic is just the special case for elements of type image. There may be other elements that require other special logic (e.g. figure+figcaption, source+picture).

Alternatively think about how to do it all in one huge recursive call so that ripple effects of removal of subsequently handled each iteration, instead of trying to eagerly remove per element type. Unclear on this idea and not sure if it will be better.

Alternatively consider mark-sweep approach. Essentially sem-remove marks the element given, then auto-marks related dependencies in the node graph for eventual prune.

jfroelich commented 5 years ago

semremove is essentially an example of using the decorator pattern. the function wraps the builtin Element.prototype.remove. For other reasons I am not extending Element, and taking element as a parameter. So it still counts. It does the same thing as element.remove(), but with some attached pre and/or post operations to the remove operation.

jfroelich commented 5 years ago

Closing indefinitely. YAGNI. Going more generic without clear reason removes specificity. Specificity is always preferable over over-abstraction.

Can return if there is a clear use case for handling ripple effects of removal of non-image elements.