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

Allow returning a node from decorate modifier to replace a node #410

Closed
wants to merge 3 commits into from

Conversation

maier49
Copy link
Contributor

@maier49 maier49 commented Jun 24, 2019

Type: feature

The following has been addressed in the PR:

Description:
Modifies decorate so that returning a node or value from the modifier function will replace it in the tree. It excludes undefined from the type so we can identify if something was actually returned.
Resolves #298

@maier49 maier49 requested a review from matt-gadd June 24, 2019 22:45
import { isWNode, isVNode } from './vdom';

const slice = Array.prototype.slice;
const hasOwnProperty = Object.prototype.hasOwnProperty;

export interface Modifier<T extends DNode> {
(dNode: T, breaker: () => void): void;
(dNode: T, breaker: () => void): void | VNode | WNode | null | string | boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this not just be void | DNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I didn't do that was because it's checking if it's a new node based on whether the return is strictly equal to undefined. DNode includes undefined so if they returned undefined as a new node it wouldn't be picked up.

If that's a problem I could add another callback to pass the new node to instead or something to avoid the ambiguity?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, it seems like we'd want to support being able to return undefined right?

@maier49
Copy link
Contributor Author

maier49 commented Jul 8, 2019

After some more discussion, this functionality is going to be implemented as a separate function rather than being added to the current decorate functionality.

@maier49 maier49 closed this Jul 8, 2019
@maier49 maier49 deleted the 298-decorate-replace-node branch July 8, 2019 17:31
@maier49 maier49 mentioned this pull request Jul 8, 2019
3 tasks
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.

Allow decorate to return a new node
2 participants