Skip to content

onParentChange callbacks #137

@raquo

Description

@raquo

Laminar elements can in theory be moved from one parent to another without unmounting. Few people knowingly use that feature, but it's possible, especially in Laminar 15.x.x. In those cases, certain advanced use cases (Frontroute URL routing, or integration with third party JS libs) might require notifications about such moves.

I think I can implement onBeforeParentChange and onAfterParentChange callbacks at no performance or complexity cost to users who don't need them. I'm not yet sure which one of those I will implement (feedback welcome). I do not plan to implement any other helper methods (*bind, *insert, etc.). I'm also not yet sure if these callbacks should fire on any parent change, or only if the element is mounted and remains mounted after the change.

Also, if the callback is to provide a reference to the next or previous parent, make sure this does not jeopardize GC – by the time the callback finishes, the reference to the old parent should be GC-d if it's not actually used, even if the callback spawned other closures (that also have access to the old parent reference, but don't use it). Figure out how to test for that.

Requested by @yurique

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions