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

Refactor/term view #21

Merged
merged 4 commits into from
Dec 19, 2017
Merged

Refactor/term view #21

merged 4 commits into from
Dec 19, 2017

Conversation

tomchentw
Copy link
Collaborator

@tomchentw tomchentw commented Dec 5, 2017

Depends on

#20

Description

  • Move list of Rows to a components/Screen
  • Refactor components/ImagePreviewer with render props pattern
  • Handle image preview logic inside components/Screen
  • Remove unused properties of term_view

Screenshots

screen shot 2017-12-13 at 10 37 27 pm

screen shot 2017-12-13 at 10 37 41 pm

@tomchentw
Copy link
Collaborator Author

Ping @robertabcd for reviewing

@tomchentw
Copy link
Collaborator Author

@robertabcd done rebasing.

Could you consider adding me to the collaborators of your repo after turning on "Protected branches on dev"? It's simpler to push branches directly here.

@robertabcd
Copy link
Owner

Yes, I'm just thinking about that. I only disabled force-push and deletion on dev branch. You can just push there. But if you'd like it to be reviewed, you can still send create PR.

@tomchentw
Copy link
Collaborator Author

I don't think GitHub has the mode for forcing all changes via Pull Requests even for collaborators? (if it does, please let me know). Anyways, I'll still create PRs for reviewing since it's easier to track changes :)
Thanks

@tomchentw tomchentw mentioned this pull request Dec 13, 2017
@tomchentw tomchentw requested a review from robertabcd December 13, 2017 07:34
@tomchentw tomchentw self-assigned this Dec 13, 2017
export const of = src => Promise.resolve({ src });

export const makeSrcResolver = ({ src }) =>
resolvers.reduceRight((acc, resolver) => {
Copy link
Owner

Choose a reason for hiding this comment

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

I feel like this is a bit showing off. I prefer something like
resolvers.find(r => r.test(src)).request(src)
which expresses the intention better.
You can use Array#unshift to make it insert at front.

return ReactDOM.render(
<Screen
lines={lines}
forceWidth={forceWidth}
showsLinkPreviews={showsLinkPreviews}
enableLinkInlinePreview={showsLinkPreviews}
enableLinkHoverPreview={enablePicPreview}
Copy link
Owner

Choose a reason for hiding this comment

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

Can you change to just use enableLinkInlinePreview and enableLinkHoverPreview in this function only? I think this is better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what you mean here. Did you mean to align the prop names with the local variable names?

Copy link
Owner

Choose a reason for hiding this comment

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

I mean the prop names are good, so just use them as function parameter names. But just change the names in this function, no need to change the whole project.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's what I thought. Thanks!


const register = resolvers.push.bind(resolvers);

register({
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add one line of comment before each register on which this resolver is for?


export const of = src => Promise.resolve({ src });

export const makeSrcResolver = ({ src }) =>
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe just use the verb resolve, it returns a Promise that does the resolving.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed to resolveSrcToImageUrl

height: img.height
});
img.onerror = reject;
img.src = src;
Copy link
Owner

Choose a reason for hiding this comment

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

Is this to preload image or to make sure it's a image? I think it should also do a simple check like in prePicRel before sending a request. We don't want to load every link user hovers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just preload image.
The non-parsable links are now handled in promise reject case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I realized that prePicRel is no longer called in any places so I removed it (correct me if I'm wrong).

Copy link
Owner

Choose a reason for hiding this comment

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

I see. Call to that function was removed in 8618472, so it currently only loads whitelisted sites. It might be good to resurrect that back later. It doesn't have to be this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. It's used here:

s0 += '<a scol="'+col+'" class="y q'+this.deffg+' b'+this.defbg+'" href="' +ch.getFullURL() + '"' + this.prePicRel( ch.getFullURL()) + ' rel="noreferrer" target="_blank" srow="'+row+'">';

But I can't really tell why we need prePicRel with type=? on the anchor tag. Mind to open an issue with more detailed description instead?

Copy link
Owner

Choose a reason for hiding this comment

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

To my understanding, it's used to annotate that the link is an image. Later, the it uses css selector to find all the images and does further processing:

".main a[type='p']",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. Created #25

return 20;
};

ImagePreviewer.renderOnHover = ({ left, top, src, height }) => (
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe move the two branch out. So this could be
{src ? <Image {...props}> : <Spinner {...props}>}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah but again, I don't meant to divide React component extensively at the moment. Just want to keep it as simple as possible and do the refactoring in the future.

Copy link
Owner

Choose a reason for hiding this comment

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

Ack.

};

render() {
return this.props.render({
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I just choose render props over dynamic type due to the reasons:

  • We're unsure whether the extracted types will be reused again, so just keep it as simple as possible.
  • Render function don't create an extra layer of react components in the render tree

Copy link
Owner

Choose a reason for hiding this comment

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

Ack.

return this.props.render({
...this.props,
request: undefined,
...this.state.value
Copy link
Owner

Choose a reason for hiding this comment

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

I feel like it should explicit say which prop to pass rather than this ... hack and remove prop using request: undefined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The ... operator is used widely and it's just the equivalent of Object.assign. Again, it keeps flexibility of defining react components/render functions here

@tomchentw
Copy link
Collaborator Author

@robertabcd anyway, I've made some changes according to your comments. Let me know if that looks good.

Copy link
Owner

@robertabcd robertabcd left a comment

Choose a reason for hiding this comment

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

Thanks!

height: img.height
});
img.onerror = reject;
img.src = src;
Copy link
Owner

Choose a reason for hiding this comment

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

I see. Call to that function was removed in 8618472, so it currently only loads whitelisted sites. It might be good to resurrect that back later. It doesn't have to be this PR.

@robertabcd robertabcd merged commit 53bd800 into robertabcd:dev Dec 19, 2017
@tomchentw tomchentw deleted the refactor/term_view branch December 19, 2017 02:15
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.

2 participants