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

Remove expressive layouts code duplication #1225

Merged
merged 1 commit into from
May 21, 2020

Conversation

ang-zeyu
Copy link
Contributor

@ang-zeyu ang-zeyu commented May 20, 2020

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [x] Other, please explain: small code refactor

What is the rationale for this request?
Merge the logic for expressive layouts in parser into includeFile

What changes did you make? (Give an overview)

  • merge said logic ( the only difference was additionalVariables, which is introduced to includeFile )
  • move file I/O of includeFile into Page.js instead which was the case for includeData for expressive layouts ( small change, but I think its cleaner to move the initial I/O into Page.js )

Is there anything you'd like reviewers to focus on?
na

Testing instructions:

  • npm run test

Proposed commit message: (wrap lines at 72 characters)
Remove expressive layouts code duplication

@ang-zeyu ang-zeyu requested a review from marvinchin May 20, 2020 12:56
const markbinder = new MarkBind();
const template = {};
template[LAYOUT_PAGE_BODY_VARIABLE] = pageData;
generateExpressiveLayout(pageData, fileConfig, markbinder) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

passing the parser (markbinder) isn't very clean, but will be dealt with in #1189 in full (making it an instance variable)

Copy link
Contributor

@marvinchin marvinchin left a comment

Choose a reason for hiding this comment

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

The refactor looks good! Just a couple of thoughts about lifting the I/O part up to Page.js:

  • Leaving it in will reduce duplication of the fs.readFileAsync call we have to make before every includeFile call.
  • It kinda makes sense semantically (to me at least) that includeFile does the reading of the file. Also, since there should be no other reason for us to use the file content outside of this function, I think not having to pass the file content to includeFile will make the call site a little cleaner.

What are your thoughts about this?

@ang-zeyu
Copy link
Contributor Author

The refactor looks good! Just a couple of thoughts about lifting the I/O part up to Page.js:

  • Leaving it in will reduce duplication of the fs.readFileAsync call we have to make before every includeFile call.
  • It kinda makes sense semantically (to me at least) that includeFile does the reading of the file. Also, since there should be no other reason for us to use the file content outside of this function, I think not having to pass the file content to includeFile will make the call site a little cleaner.

What are your thoughts about this?

Hmm, my viewpoint was from a perspective of concerns - I think parser should be concerned with as little file I/O as possible, because it only 'parses' ( and also 'renders' ).
That said many other areas of parser still necessarily do file i/o ( includes / imports ), and I don't see it going away unless we implement a file cache of sorts ( I think there was an issue about this that fizzled though since the benefits were marginal ( modern ssds are too fast 🌚 ) ).

Its a really small thing though, I'm fully open to reverting it. What do you think?

@marvinchin
Copy link
Contributor

That makes sense as well. I'm happy to go with this and move towards removing I/O concerns from the parser. Let's get the conflicts resolved and we can get this in!

@ang-zeyu ang-zeyu force-pushed the refactor-expressive-layouts branch from cb9f0ed to 7bb7462 Compare May 21, 2020 12:36
@ang-zeyu
Copy link
Contributor Author

That makes sense as well. I'm happy to go with this and move towards removing I/O concerns from the parser. Let's get the conflicts resolved and we can get this in!

Done!

Copy link
Contributor

@marvinchin marvinchin left a comment

Choose a reason for hiding this comment

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

LGTM

@ang-zeyu ang-zeyu added this to the v2.15.0 milestone May 21, 2020
@ang-zeyu ang-zeyu merged commit 3f4aa36 into MarkBind:master May 21, 2020
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.

None yet

2 participants