Skip to content

Commit

Permalink
Merge pull request hotwired#1094 from seanpdoyle/remove-window-turbo-…
Browse files Browse the repository at this point in the history
…reference

Import `session` instead of reading `window.Turbo.session`
  • Loading branch information
jorgemanrubia authored Dec 2, 2023
2 parents f92fb0f + 7a7c6e2 commit 5c48398
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { PageRenderer } from "./drive/page_renderer"
import { PageSnapshot } from "./drive/page_snapshot"
import { FrameRenderer } from "./frames/frame_renderer"
import { FormSubmission } from "./drive/form_submission"
import { StreamActions } from "./streams/stream_actions"
import { fetch, recentRequests } from "../http/fetch"

const session = new Session(recentRequests)
const { cache, navigator } = session
export { navigator, session, cache, PageRenderer, PageSnapshot, FrameRenderer, StreamActions, fetch }
export { navigator, session, cache, PageRenderer, PageSnapshot, FrameRenderer, fetch }

/**
* Starts the main session.
Expand Down
4 changes: 3 additions & 1 deletion src/core/streams/stream_actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { session } from "../"

export const StreamActions = {
after() {
this.targetElements.forEach((e) => e.parentElement?.insertBefore(this.templateContent, e.nextSibling))
Expand Down Expand Up @@ -33,6 +35,6 @@ export const StreamActions = {
},

refresh() {
window.Turbo.session.refresh(this.baseURI, this.requestId)
session.refresh(this.baseURI, this.requestId)
}
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import "./polyfills"
import "./elements"
import "./script_warning"
import { StreamActions } from "./core/streams/stream_actions"

import * as Turbo from "./core"

window.Turbo = Turbo
window.Turbo = { ...Turbo, StreamActions }
Turbo.start()

export { StreamActions }
export * from "./core"
export * from "./elements"
export * from "./http"

0 comments on commit 5c48398

Please sign in to comment.