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

Rewrote the asset build pipeline #1474

Closed
wants to merge 5 commits into from
Closed

Rewrote the asset build pipeline #1474

wants to merge 5 commits into from

Conversation

bcardarella
Copy link
Contributor

See phoenixframework/phoenix#4337 for details

A few differences from the Phoenix PR are due to this repo using Jest and not Mocha to test the JavaScript. Jest has been updated to latest and the previously existing settings in package.json have been moved over to the jest.config.js file

@bcardarella
Copy link
Contributor Author

Note: for the npm tests to pass the phoenix node module needs to be published with the new es6 module implementation.

Comment on lines +10 to +13
import LiveSocket from "phoenix_live_view/live_socket"
export {
LiveSocket
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import LiveSocket from "phoenix_live_view/live_socket"
export {
LiveSocket
}
export { default as LiveSocket } from "phoenix_live_view/live_socket"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not exporting LiveSocket as default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I take that back. There appears to be some inconsistency in the existing JS. LiveScocket is being exported as default and as a named export: https://github.com/phoenixframework/phoenix_live_view/blob/master/assets/js/phoenix_live_view.js#L3018

The generated app.js from Phoenix assumes named export: https://github.com/phoenixframework/phoenix/blob/master/installer/templates/phx_assets/app.js#L18

The documentation in Elixir assumed default export: https://github.com/phoenixframework/phoenix_live_view/blob/master/lib/phoenix_live_view.ex#L178

but that code snippet is not consistent with the app.js code: https://github.com/phoenixframework/phoenix/blob/master/installer/templates/phx_assets/app.js#L18

I am OK adding the default export, I just need @chrismccord to weigh in on what the intention is here. I suspect somewhere along the way this detail got confused and we ended up with both ways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we want we can deprecate the default export by adding a console.log message indicating that default is deprecated in favor of the named import, then align all documentation around the named import.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bcardarella that line should export the default export as a named export.

Basically the same you wrote in one statement.

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 I see, that's interesting. I didn't know you could do both at once. Let me get feedback from @chrismccord on the default vs named export preference. If a change is going to be made now would be the time. If no change will be made I'll happily change to your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spoke with @chrismccord and we're going to just go with named export and not have a default export.


LiveImgPreview: {
mounted(){
this.ref = this.el.getAttribute("data-phx-entry-ref")
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR is a great resource for learning how to separate concerns. Thank you.

I'm curious, is this attribute not constantised because it's the only place it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This particular LOC wasn't changed when extracted into the class-per-file style. After this is merged and vetted we can probably take a look at some refactors.

@chrismccord
Copy link
Member

Merged manually in master ❤️❤️❤️🐥🔥

@maennchen
Copy link
Contributor

What is the reason that the production source maps were removed (introduced in #1385)?

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

4 participants