Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks optimisations and refactorings #116

Merged
merged 1 commit into from Dec 7, 2017
Merged

Conversation

mariusmuja
Copy link
Collaborator

Currently, even if there are no hook sinks present on a VNode, there are empty insert/update/create hooks created for all the VNodes. This PR leaves the hooks as undefined in case there are no hook sinks present.

The PR also adds support for the prepatch/postpatch hooks. I needed postpatch for frameworks such Material Design Lite and Materialize that require dynamic components to be "upgraded" after they are inserted in the DOM (using the update hooks did not work, the "upgrading" has to happen after the snabbdom patch is completed).

final case class DestroyHook(observer: Observer[Element]) extends Hook
final case class UpdateHook(observer: Observer[(Element, Element)]) extends Hook

sealed trait HookSingle extends Hook {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these traits generic? So we have def observer: Observer[T]. We can later pattern match on the value when mapping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a way to make this trait generic and combine the functions createHookSingle etc. , great. But if that turns out to be impractical, I'm fine with this solution.

Copy link
Member

@fdietze fdietze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I also thought about adding the postpatch-hook, but never finished it.

Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants