Skip to content

Commit

Permalink
feat: Export surface hooks as a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-suprunenko committed Oct 5, 2021
1 parent a0262a5 commit 837503c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ npm-debug.log

# Ignore assets that are produced by build tools.
/priv/static/assets/
!/priv/static/assets/hooks.js

node_modules
.DS_Store
Expand Down
16 changes: 1 addition & 15 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
// webpack automatically bundles all modules in your
// entry points. Those entry points can be configured
// in 'webpack.config.js'.
//
// Import deps with the dep name or local files with a relative path, for example:
//
// import {Socket} from 'phoenix'
// import socket from './socket'
//
import 'phoenix_html'
import { Socket } from 'phoenix'
import { LiveSocket } from 'phoenix_live_view'
import Alpine from 'alpinejs'

import Datepicker from './hooks/datepicker'

const hooks = {
Datepicker
}
import { hooks } from './hooks'

let csrfToken = document
.querySelector("meta[name='csrf-token']")
Expand Down
1 change: 1 addition & 0 deletions assets/js/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as hooks } from './hooks/index'
4 changes: 1 addition & 3 deletions assets/js/hooks/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Datepicker = {
export default {
updated() {
if (this.el.value) {
const newVal = this.el.dataset.pendingVal
Expand All @@ -8,5 +8,3 @@ const Datepicker = {
}
}
}

export default Datepicker
5 changes: 5 additions & 0 deletions assets/js/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { default as Datepicker } from './datepicker'

export default {
Datepicker
}
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ config :phoenix, :json_library, Jason
config :esbuild,
version: "0.12.18",
default: [
args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
args: ~w(js/app.js js/hooks.js --bundle --target=es2016 --outdir=../priv/static/assets),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
Expand Down
19 changes: 19 additions & 0 deletions priv/static/assets/hooks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 837503c

Please sign in to comment.