Skip to content

Commit

Permalink
Delegate Turbo.session properties to Turbo.config
Browse files Browse the repository at this point in the history
Follow-up to comment on [238ec26][]

[hotwired#1216][] unintentionally removed support for
the `Turbo.session.drive` boolean property and the
`Turbo.session.formMode` string property.

This commit re-introduces that support by delegating reads and writes to
those properties to their corresponding `Turbo.config` versions.

[hotwired#1216]: hotwired#1216
[238ec26]: hotwired@238ec26#commitcomment-145954235
  • Loading branch information
seanpdoyle committed Aug 28, 2024
1 parent 4d65288 commit c6ec8d3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ export class Session {
return config.drive.progressBarDelay
}

set drive(value) {
config.drive.enabled = value
}

get drive() {
return config.drive.enabled
}

set formMode(value) {
config.forms.mode = value
}

get formMode() {
return config.forms.mode
}

get location() {
return this.history.location
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/drive_disabled.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
})
</script>
<script>
Turbo.config.drive = false
Turbo.config.drive.enabled = false
</script>
</head>
<body>
Expand Down
19 changes: 19 additions & 0 deletions src/tests/unit/export_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,28 @@ test("Turbo interface", () => {
assert.equal(typeof Turbo.cache.clear, "function")
assert.equal(typeof Turbo.navigator, "object")
assert.equal(typeof Turbo.session, "object")
assert.equal(typeof Turbo.session.drive, "boolean")
assert.equal(typeof Turbo.session.formMode, "string")
assert.equal(typeof Turbo.fetch, "function")
})

test("Session interface", () => {
const { session, config } = Turbo

assert.equal(true, session.drive)
assert.equal(true, config.drive.enabled)
assert.equal("on", session.formMode)
assert.equal("on", config.forms.mode)

session.drive = false
session.formMode = "off"

assert.equal(false, session.drive)
assert.equal(false, config.drive.enabled)
assert.equal("off", session.formMode)
assert.equal("off", config.forms.mode)
})

test("StreamActions interface", () => {
assert.equal(typeof StreamActions, "object")
})

0 comments on commit c6ec8d3

Please sign in to comment.