Skip to content

Commit

Permalink
Move Cache instantiation to Session (#1024)
Browse files Browse the repository at this point in the history
When the `Cache` class was [introduced in a54ac17][], it depended on a
`Session` instance. When it was [modified in f86a376][], that dependency
was no longer necessary.

This commit preserves the export of the `Turbo.cache` property while
re-arranging the location it's declared. Instead of instantiating the
`Cache` instance in `@hotwired/turbo/core/`, this commit defines it as a
property on the `Session` instance.

[introduced in a54ac17]: a54ac17
[modified in f86a376]: f86a376
  • Loading branch information
seanpdoyle authored Oct 23, 2023
1 parent e087856 commit 485115d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/core/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { setMetaContent } from "../util"
import { SnapshotCache } from "./drive/snapshot_cache"

export class Cache {
constructor(session) {
this.session = session
}

clear() {
this.store.clear()
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Session } from "./session"
import { Cache } from "./cache"
import { PageRenderer } from "./drive/page_renderer"
import { PageSnapshot } from "./drive/page_snapshot"
import { FrameRenderer } from "./frames/frame_renderer"
import { FormSubmission } from "./drive/form_submission"

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

export { StreamActions } from "./streams/stream_actions"
Expand Down
2 changes: 2 additions & 0 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { clearBusyState, dispatch, findClosestRecursively, getVisitAction, markA
import { PageView } from "./drive/page_view"
import { FrameElement } from "../elements/frame_element"
import { Preloader } from "./drive/preloader"
import { Cache } from "./cache"

export class Session {
navigator = new Navigator(this)
Expand All @@ -33,6 +34,7 @@ export class Session {
formLinkClickObserver = new FormLinkClickObserver(this, document.documentElement)
frameRedirector = new FrameRedirector(this, document.documentElement)
streamMessageRenderer = new StreamMessageRenderer()
cache = new Cache()

drive = true
enabled = true
Expand Down

0 comments on commit 485115d

Please sign in to comment.