-
Notifications
You must be signed in to change notification settings - Fork 819
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
Rework render flow. #297
Rework render flow. #297
Conversation
src/render.js
Outdated
findPageData(children[i], depth + 1); | ||
} | ||
return accumulated; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear to me why this method exists. It appears to have recursive functionality, but the nested call to findPageData
doesn't pass through the accumulated array. So really it recursively searches the tree, but only returns top level results.
I have completely removed this method as I see no reason not to simply loop through the children of the Document
component.
src/resets.js
Outdated
for (let l = 0; l < layers.count() - 1; l += 1) { | ||
const layer = layers.objectAtIndex(l); | ||
layer.removeFromParent(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was especially puzzling to me.
From a code standpoint, I don't understand Skip last child since it is the container itself
... The values of container.children()
are only the containers children. It would make no sense for container.children()
to contain itself.
When manually running this piece of code, it did exactly what I expected it to... It left a child on the page. To be more clear. If I create a page, I insert and Artboard on that page, and I run restLayer
on that page, the Artboard is not removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be a user error of some sort, but upon further investigation this check does appear necessary when using layer.children()
. However, we may be able to bypass this check by instead utilizing layer.layers()
which appears to return only the direct descendants of the layer.
9f811b8
to
aa3dfcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some good stuff in there but it should probably be rebased on top of #254 which cleans up a bit how we handle the container. Could you perhaps review that PR so I can merge it?
src/render.js
Outdated
const tree = buildTree(element); | ||
|
||
if (tree.type === 'document' && container) { | ||
throw Error('Cannot render `Document` component into a container'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's right. What if I pass a document as the container? I might not want to render into the current document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/render.js
Outdated
}); | ||
} | ||
return tree.children.map((child, i) => { | ||
const page = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we add a check to make sure the child is a Page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can... would you want to throw if it isn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that'd be nice
src/render.js
Outdated
// assume if name is set on this nested page, the intent is to overwrite | ||
// the name of the page it is getting rendered into | ||
if (tree.props.name) { | ||
container.setName(tree.props.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Yep. After reviewing #254 it is clear that this work should be rebased ontop of it. I will wait for it's merge and then push appropriate updates. Thanks for the set of 👀@mathieudutour |
3952049
to
e55be5f
Compare
…of entire `Document`
e55be5f
to
5aa564c
Compare
@mathieudutour - I have refreshed this PR of off current master (which now includes #254). When you have a moment, could you please give this a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we really need to forbid rendering into the Symbols
page. There is nothing special about in Sketch except being the default location where symbols are going but they can be created in any page and you can any type of layers to the Symbols page
I more or less agree with your sentiment, but I think that is a larger question that would need to be addressed in a standalone task. The current implementation of symbols makes a few assumptions about the Symbols page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good. Can you create the follow up issue so that we don't forget?
[Edited: 2018/05/07]
Breaking Changes (kind of)
container
on therender
method. Previously if you explicitly passed in the "Symbols" pages as a container, it would create a new page and render onto that. I would consider that to be unexpected behavior.Document
component into a node intended to be a child of Document. Previous behavior was unexpected. It would result in reseting the currently selected page only, and then it would additionally render all child pages defined within the passedDocument
. This would essentially result in pages indefinitely being added to the document upon calling render. This may possibly close Multiple pages are created when using makeSymbol after saving #262.Enhancements
RedBox
. The previous implementation would not respect the passed in container. It would always render theRedBox
into the currently selected page. This could have real negative consequences, by accidentally rendering over pages that were manually constructed. The new behavior will first check for a passed in container, if it does not exist, it will either render onto the currently selected page, or it will create a new page if the currently selected page is the "Symbols" page.Page
component into a container passed through therender
method. This allows for rendering multipleArtboard
s onto an existing page. This would close Add Canvas component (enables rendering multiple Artboard's on existing page) #291 as there would no longer be a need for theCanvas
component.Additional Notes
defaultProps
fromPage
component (enables auto-incrementing page name) #296: This is a larger concern than just this particular PR, but I don't see where or how I can create tests to confirm functionality that involves Sketch's behavior