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

[wip] Migrate to React #91

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open

[wip] Migrate to React #91

wants to merge 47 commits into from

Conversation

ryanscottaudio
Copy link

@ryanscottaudio ryanscottaudio commented Apr 11, 2017

TODO:

  • Fix onMouseUp not firing
  • Fix cut and paste
  • Fix issue with selections

// handling for, like undo/redo etc.
const zKeyCode = 90;
if (e.metaKey && e.keyCode === zKeyCode) {
this.setState({ undone: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do?

Copy link
Author

Choose a reason for hiding this comment

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

makes it so that the linter doesn't throw because we're not using this in a class method. i could just extract the method but it seemed like it made more sense for an example to have it on the class


const app = tree(<Article items={items} onUpdate={onUpdate} getCustomKeyDown={getCustomKeyDown} />);
return () => {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not return an empty function here, we only want to return a handler if this is an event we want to handle.

Copy link
Author

Choose a reason for hiding this comment

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

ok; we have to return something for the linter, so i'll return undefined


```sh
npm install article-json-to-contenteditable --save
```
## Example
Copy link
Contributor

Choose a reason for hiding this comment

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

If you move the example/client.js file to the root and name it example.js I think it will be included in the readme automatically. Might be nice, wdyt?

Copy link
Author

Choose a reason for hiding this comment

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

definitely!

return;
}
// We need to update the figure without touching the iframe
// to avoid reloading it for every update.
const oldCaption = oldFigure.querySelector('figcaption');
const newCaption = newFigure.querySelector('figcaption');
const oldCaption = oldFigure.getElementsByTagName('figcaption')[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these changed from querySelector to getElementsByTagName?

Copy link
Author

Choose a reason for hiding this comment

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

flow can apparently understand getElementsByTagName better

Copy link
Author

Choose a reason for hiding this comment

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

lib/patch-dom.js Outdated
const oldCaption = oldFigure.querySelector('figcaption');
const newCaption = newFigure.querySelector('figcaption');
const oldCaption = oldFigure.getElementsByTagName('figcaption')[0];
const newCaption = newFigure.getElementsByTagName('figcaption');
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be newFigure.getElementsByTagName('figcaption')[0]

@@ -63,8 +71,8 @@ export default ({oldArticleElm, newArticleElm}) => {
case UPDATE:
if (isIframeEmbed(prev)) {
queue.update.push(() => updateIframeEmbed({
oldFigure: oldArticleElm.childNodes[pos],
newFigure: next
oldFigure: oldArticleElm.children[pos],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use .children instead of .childNodes?

Copy link
Author

Choose a reason for hiding this comment

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

it doesn't work with Flow for some reason

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, ok strange. Is flow not complaining about the other places we're using childNodes in here?

It's probably fine to change this here, since we actually are looking for an element and not a node. Not sure our tests are covering this a 100% though so we should just make sure manually that this is working as expected.

lib/index.js Outdated
@@ -116,7 +117,8 @@ const setup = ({ customTextFormattings, parseFigureProps, customCaption }: Setup
// Check props first without rendering,
// no need to go through with rendering if we know nothing has changed.
const propsHasUpdated = this.props.selections !== nextProps.selections ||
this.props.contentEditable !== nextProps.contentEditable;
this.props.contentEditable !== nextProps.contentEditable ||
!deepEqual(this.props.items, nextProps.items, { strict: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

@ryanscottaudio Hey, did this make a performance difference? Realizing now it might do that in the example, but where we use this in our editor we're using immutable data, so just checking this.props.items !== nextProps.items used to be enough before at least.

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