Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Decoration component #476

Merged
merged 7 commits into from
Jan 30, 2017
Merged

Decoration component #476

merged 7 commits into from
Jan 30, 2017

Conversation

smashwilson
Copy link
Contributor

Split the Decoration component and its tests out from #385 so that @BinaryMuse can start using it in the GitHub integration.

const optionKeys = Object.keys(this.props.options);
const nextOptionKeys = Object.keys(nextProps.options);

if (optionKeys.length !== nextOptionKeys.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have access to a shallowEqual check we can use here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, React does have a shallowCompare utility, but it's deprecated and gated in a separate dependency. Lodash also has _.isEqualWith which could be used to do this pretty easily.

Worth adding a new dependency for, do you think? Personally I'm leaning toward the lodash route.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I just spent a fair amount of time trying to get this to work with Lodash, but I didn't have any luck (...possibly because it's Monday). In any case, I'll ship with this and we can touch up later 😄

Copy link
Contributor

@BinaryMuse BinaryMuse left a comment

Choose a reason for hiding this comment

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

Looks super reasonable, and we can iterate if needed. A few comments inline.

static defaultProps = {
options: {},
position: 'head',
getItem: ({portal, subtree}) => subtree,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should default this to returning the portal, instead of the React subtree component. IIRC we should only really reach into the subtree in the case of using Etch components (to call getWrappedComponent on the EtchWrapper)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Ah right you are.

I'd had it in my mind that the portal <div> was rendered in the detached DOM tree and the subtree was root of the tree rendered into the container, but re-reading the source, I see the portal <div> is the root (which makes more sense anyway).

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 portal ref assignment gets the instance, not the DOM element. I've changed it to default to portal.node to return the root element instead. If that's wrong we can always change it later 😁


this.decoration = this.props.editor.decorateMarker(this.props.marker, options);
this.subscriptions.add(this.decoration.onDidDestroy(() => {
this.decoration = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also clear out the subscription when it gets destroyed? If there's only one at a time a common pattern is

this.subscription = this.thing.onDidDestroy(() => {
  this.thing = null
  this.subscription.dispose();
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 Oops, thanks for the catch!

Also, I think you just fixed a bug I'd noticed when I'd taken the conflict resolution PR for a spin 🎯

@BinaryMuse
Copy link
Contributor

BinaryMuse commented Jan 30, 2017 via email

@smashwilson
Copy link
Contributor Author

The portal implements the Atom view interface so should work

Oh! Good to know.

@smashwilson smashwilson force-pushed the aw-decoration-component branch from 922d1ab to c4869d6 Compare January 30, 2017 17:27
@smashwilson smashwilson merged commit 6a3303e into master Jan 30, 2017
@smashwilson smashwilson deleted the aw-decoration-component branch January 30, 2017 18:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants