@@ -3,6 +3,7 @@ import * as Sentry from '@sentry/browser'
3
3
import topbar from 'topbar'
4
4
import { Socket } from 'phoenix'
5
5
import { LiveSocket } from 'phoenix_live_view'
6
+ import { hooks as colocatedHooks } from 'phoenix-colocated/demo'
6
7
// in your app.js, just use 'backpex' like this:
7
8
// import { Hooks as BackpexHooks } from 'backpex'
8
9
import { Hooks as BackpexHooks } from '#backpex'
@@ -34,7 +35,7 @@ const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute
34
35
35
36
const liveSocket = new LiveSocket ( '/live' , Socket , {
36
37
params : { _csrf_token : csrfToken } ,
37
- hooks : { ...BackpexHooks }
38
+ hooks : { ...BackpexHooks , ... colocatedHooks }
38
39
} )
39
40
40
41
liveSocket . connect ( )
@@ -43,3 +44,38 @@ liveSocket.connect()
43
44
* Globals
44
45
*/
45
46
window . liveSocket = liveSocket
47
+
48
+ // The lines below enable quality of life phoenix_live_reload
49
+ // development features:
50
+ //
51
+ // 1. stream server logs to the browser console
52
+ // 2. click on elements to jump to their definitions in your code editor
53
+ //
54
+ if ( process . env . NODE_ENV === 'development' ) {
55
+ window . addEventListener ( 'phx:live_reload:attached' , ( { detail : reloader } ) => {
56
+ // Enable server log streaming to client.
57
+ // Disable with reloader.disableServerLogs()
58
+ reloader . enableServerLogs ( )
59
+
60
+ // Open configured PLUG_EDITOR at file:line of the clicked element's HEEx component
61
+ //
62
+ // * click with "c" key pressed to open at caller location
63
+ // * click with "d" key pressed to open at function component definition location
64
+ let keyDown
65
+ window . addEventListener ( 'keydown' , function ( e ) { keyDown = e . key } )
66
+ window . addEventListener ( 'keyup' , function ( e ) { keyDown = null } )
67
+ window . addEventListener ( 'click' , function ( e ) {
68
+ if ( keyDown === 'c' ) {
69
+ e . preventDefault ( )
70
+ e . stopImmediatePropagation ( )
71
+ reloader . openEditorAtCaller ( e . target )
72
+ } else if ( keyDown === 'd' ) {
73
+ e . preventDefault ( )
74
+ e . stopImmediatePropagation ( )
75
+ reloader . openEditorAtDef ( e . target )
76
+ }
77
+ } , true )
78
+
79
+ window . liveReloader = reloader
80
+ } )
81
+ }
0 commit comments