Skip to content

Commit

Permalink
Turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Dec 8, 2020
1 parent 4262fea commit 0fa64b0
Show file tree
Hide file tree
Showing 40 changed files with 134 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"type": "node",
"request": "launch",
"name": "Turbolinks: Debug browser tests",
"name": "Turbo: Debug browser tests",
"cwd": "${workspaceFolder}",
"port": 9229,
"outputCapture": "std",
Expand Down
10 changes: 5 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "Turbolinks: Build dist directory",
"label": "Turbo: Build dist directory",
"type": "shell",
"command": "yarn build",
"group": {
Expand All @@ -16,19 +16,19 @@
]
},
{
"label": "Turbolinks: Run tests",
"label": "Turbo: Run tests",
"type": "shell",
"dependsOn": "Turbolinks: Build dist directory",
"dependsOn": "Turbo: Build dist directory",
"command": "yarn test",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Turbolinks: Start dev server",
"label": "Turbo: Start dev server",
"type": "shell",
"dependsOn": "Turbolinks: Build dist directory",
"dependsOn": "Turbo: Build dist directory",
"command": "yarn start",
"problemMatcher": []
}
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
{
"name": "turbolinks",
"version": "5.3.0-beta.1",
"description": "Turbolinks makes navigating your web application faster",
"name": "@hotwired/turbo",
"version": "7.0.0-beta.1",
"description": "Turbo makes navigating your web application faster",
"module": "dist/index.js",
"main": "dist/turbolinks.js",
"main": "dist/turbo.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/turbolinks/turbolinks.git"
"url": "git+https://github.com/hotwired/turbo.git"
},
"keywords": [
"turbolinks",
"hotwire",
"turbo",
"browser",
"pushstate"
],
"author": "javan, packagethief, sstephenson",
"license": "MIT",
"bugs": {
"url": "https://github.com/turbolinks/turbolinks/issues"
"url": "https://github.com/hotwired/turbo/issues"
},
"homepage": "https://github.com/turbolinks/turbolinks#readme",
"homepage": "https://turbo.hotwire.dev",
"devDependencies": {
"intern": "^4.9.0",
"rollup": "^2.9.1",
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export default [
{
input: "src/umd.ts",
output: {
banner: `/*\nTurbolinks ${version}\nCopyright © ${year} Basecamp, LLC\n */`,
file: "dist/turbolinks.js",
banner: `/*\nTurbo ${version}\nCopyright © ${year} Basecamp, LLC\n */`,
file: "dist/turbo.js",
format: "umd",
name: "Turbolinks",
name: "Turbo",
sourcemap: true
},
...options
Expand Down
20 changes: 10 additions & 10 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,44 +190,44 @@ export class Controller implements NavigatorDelegate {
}

notifyApplicationAfterClickingLinkToLocation(link: Element, location: Location) {
return dispatch("turbolinks:click", { target: link, data: { url: location.absoluteURL }, cancelable: true })
return dispatch("turbo:click", { target: link, data: { url: location.absoluteURL }, cancelable: true })
}

notifyApplicationBeforeVisitingLocation(location: Location) {
return dispatch("turbolinks:before-visit", { data: { url: location.absoluteURL }, cancelable: true })
return dispatch("turbo:before-visit", { data: { url: location.absoluteURL }, cancelable: true })
}

notifyApplicationAfterVisitingLocation(location: Location) {
return dispatch("turbolinks:visit", { data: { url: location.absoluteURL } })
return dispatch("turbo:visit", { data: { url: location.absoluteURL } })
}

notifyApplicationBeforeCachingSnapshot() {
return dispatch("turbolinks:before-cache")
return dispatch("turbo:before-cache")
}

notifyApplicationBeforeRender(newBody: HTMLBodyElement) {
return dispatch("turbolinks:before-render", { data: { newBody }})
return dispatch("turbo:before-render", { data: { newBody }})
}

notifyApplicationAfterRender() {
return dispatch("turbolinks:render")
return dispatch("turbo:render")
}

notifyApplicationAfterPageLoad(timing: TimingData = {}) {
return dispatch("turbolinks:load", { data: { url: this.location.absoluteURL, timing }})
return dispatch("turbo:load", { data: { url: this.location.absoluteURL, timing }})
}

// Private

getActionForLink(link: Element): Action {
const action = link.getAttribute("data-turbolinks-action")
const action = link.getAttribute("data-turbo-action")
return isAction(action) ? action : "advance"
}

linkIsVisitable(link: Element) {
const container = closest(link, "[data-turbolinks]")
const container = closest(link, "[data-turbo]")
if (container) {
return container.getAttribute("data-turbolinks") != "false"
return container.getAttribute("data-turbo") != "false"
} else {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions src/fetch_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class FetchRequest {

async perform(): Promise<FetchResponse> {
const { fetchOptions } = this
dispatch("turbolinks:before-fetch-request", { data: { fetchOptions } })
dispatch("turbo:before-fetch-request", { data: { fetchOptions } })
try {
this.delegate.requestStarted(this)
const response = await fetch(this.url, fetchOptions)
Expand All @@ -96,7 +96,7 @@ export class FetchRequest {

async receive(response: Response): Promise<FetchResponse> {
const fetchResponse = new FetchResponse(response)
const event = dispatch("turbolinks:before-fetch-response", { cancelable: true, data: { fetchResponse } })
const event = dispatch("turbo:before-fetch-response", { cancelable: true, data: { fetchResponse } })
if (event.defaultPrevented) {
this.delegate.requestPreventedHandlingResponse(this, fetchResponse)
} else if (fetchResponse.succeeded) {
Expand Down
4 changes: 2 additions & 2 deletions src/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class FormSubmission {

requestStarted(request: FetchRequest) {
this.state = FormSubmissionState.waiting
dispatch("turbolinks:submit-start", { target: this.formElement, data: { formSubmission: this } })
dispatch("turbo:submit-start", { target: this.formElement, data: { formSubmission: this } })
this.delegate.formSubmissionStarted(this)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ export class FormSubmission {

requestFinished(request: FetchRequest) {
this.state = FormSubmissionState.stopped
dispatch("turbolinks:submit-end", { target: this.formElement, data: { formSubmission: this, ...this.result }})
dispatch("turbo:submit-end", { target: this.formElement, data: { formSubmission: this, ...this.result }})
this.delegate.formSubmissionFinished(this)
}

Expand Down
2 changes: 1 addition & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ interface Node {
}

interface Window {
Turbolinks: any
Turbo: any
}
2 changes: 1 addition & 1 deletion src/head_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function elementType(element: Element) {
}

function elementIsTracked(element: Element) {
return element.getAttribute("data-turbolinks-track") == "reload"
return element.getAttribute("data-turbo-track") == "reload"
}

function elementIsScript(element: Element) {
Expand Down
8 changes: 4 additions & 4 deletions src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class History {
}

update(method: HistoryMethod, location: Location, restorationIdentifier = uuid()) {
const state = { turbolinks: { restorationIdentifier } }
const state = { turbo: { restorationIdentifier } }
method.call(history, state, "", location.absoluteURL)
this.location = location
this.restorationIdentifier = restorationIdentifier
Expand All @@ -76,11 +76,11 @@ export class History {

onPopState = (event: PopStateEvent) => {
if (this.shouldHandlePopState()) {
const { turbolinks } = event.state || {}
if (turbolinks) {
const { turbo } = event.state || {}
if (turbo) {
const location = Location.currentLocation
this.location = location
const { restorationIdentifier } = turbolinks
const { restorationIdentifier } = turbo
this.restorationIdentifier = restorationIdentifier
this.delegate.historyPoppedToLocationWithRestorationIdentifier(location, restorationIdentifier)
}
Expand Down
4 changes: 2 additions & 2 deletions src/progress_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class ProgressBar {

static get defaultCSS() {
return unindent`
.turbolinks-progress-bar {
.turbo-progress-bar {
position: fixed;
display: block;
top: 0;
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ProgressBar {

createProgressElement() {
const element = document.createElement("div")
element.className = "turbolinks-progress-bar"
element.className = "turbo-progress-bar"
return element
}
}
2 changes: 1 addition & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class Renderer {
}

createScriptElement(element: Element) {
if (element.getAttribute("data-turbolinks-eval") == "false") {
if (element.getAttribute("data-turbo-eval") == "false") {
return element
} else {
const createdScriptElement = document.createElement("script")
Expand Down
8 changes: 4 additions & 4 deletions src/script_warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { unindent } from "./util"
(() => {
let element: Element | null = document.currentScript
if (!element) return
if (element.hasAttribute("data-turbolinks-suppress-warning")) return
if (element.hasAttribute("data-turbo-suppress-warning")) return

while (element = element.parentElement) {
if (element == document.body) {
return console.warn(unindent`
You are loading Turbolinks from a <script> element inside the <body> element. This is probably not what you meant to do!
You are loading Turbo from a <script> element inside the <body> element. This is probably not what you meant to do!
Load your application’s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change.
For more information, see: https://github.com/turbolinks/turbolinks#working-with-script-elements
For more information, see: https://turbo.hotwire.dev/handbook/building#working-with-script-elements
——
Suppress this warning by adding a "data-turbolinks-suppress-warning" attribute to: %s
Suppress this warning by adding a "data-turbo-suppress-warning" attribute to: %s
`, element.outerHTML)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export class Snapshot {
}

getPermanentElements() {
return array(this.bodyElement.querySelectorAll("[id][data-turbolinks-permanent]"))
return array(this.bodyElement.querySelectorAll("[id][data-turbo-permanent]"))
}

getPermanentElementById(id: string) {
return this.bodyElement.querySelector(`#${id}[data-turbolinks-permanent]`)
return this.bodyElement.querySelector(`#${id}[data-turbo-permanent]`)
}

getPermanentElementsPresentInSnapshot(snapshot: Snapshot) {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class Snapshot {
getSetting(name: string): string | undefined
getSetting(name: string, defaultValue: string): string
getSetting(name: string, defaultValue?: string) {
const value = this.headDetails.getMetaValue(`turbolinks-${name}`)
const value = this.headDetails.getMetaValue(`turbo-${name}`)
return value == null ? defaultValue : value
}
}
2 changes: 1 addition & 1 deletion src/snapshot_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class SnapshotRenderer extends Renderer {

function createPlaceholderForPermanentElement(permanentElement: PermanentElement) {
const element = document.createElement("meta")
element.setAttribute("name", "turbolinks-permanent-placeholder")
element.setAttribute("name", "turbo-permanent-placeholder")
element.setAttribute("content", permanentElement.id)
return { element, permanentElement }
}
Expand Down
6 changes: 3 additions & 3 deletions src/tests/async_script_tests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TurbolinksTestCase } from "./helpers/turbolinks_test_case"
import { TurboTestCase } from "./helpers/turbo_test_case"

export class AsyncScriptTests extends TurbolinksTestCase {
export class AsyncScriptTests extends TurboTestCase {
async setup() {
await this.goToLocation("/fixtures/async_script.html")
}

async "test does not emit turbolinks:load when loaded asynchronously after DOMContentLoaded"() {
async "test does not emit turbo:load when loaded asynchronously after DOMContentLoaded"() {
const events = await this.eventLogChannel.read()
this.assert.deepEqual(events, [])
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/additional_assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>Additional assets</title>
<link rel="stylesheet" type="text/css" href="/fixtures/test.css">
<script src="/fixtures/turbolinks.js" data-turbolinks-track="reload"></script>
<script src="/fixtures/turbo.js" data-turbo-track="reload"></script>
<script src="/fixtures/test.js"></script>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions src/tests/fixtures/async_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<html>
<head>
<meta charset="utf-8">
<title>Turbolinks</title>
<title>Turbo</title>
<script src="/fixtures/test.js"></script>
<script>
addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
var script = document.createElement("script")
script.src = "/fixtures/turbolinks.js"
script.src = "/fixtures/turbo.js"
script.setAttribute("async", "")
document.head.appendChild(script)
}, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/fixtures/async_script_2.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<meta charset="utf-8">
<title>Turbolinks</title>
<title>Turbo</title>
<script src="/fixtures/test.js"></script>
<script src="/fixtures/turbolinks.js" async></script>
<script src="/fixtures/turbo.js" async></script>
</head>
<body>
<section>
Expand Down
4 changes: 2 additions & 2 deletions src/tests/fixtures/body_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<title>Body script</title>
<script src="/fixtures/turbolinks.js" data-turbolinks-track="reload"></script>
<script src="/fixtures/turbo.js" data-turbo-track="reload"></script>
<script src="/fixtures/test.js"></script>
<meta name="turbolinks-cache-control" content="no-preview">
<meta name="turbo-cache-control" content="no-preview">
</head>
<body>
<h1>Body script</h1>
Expand Down
8 changes: 4 additions & 4 deletions src/tests/fixtures/eval_false_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<html>
<head>
<meta charset="utf-8">
<title>data-turbolinks-eval=false script</title>
<script src="/fixtures/turbolinks.js" data-turbolinks-track="reload"></script>
<title>data-turbo-eval=false script</title>
<script src="/fixtures/turbo.js" data-turbo-track="reload"></script>
<script src="/fixtures/test.js"></script>
</head>
<body>
<h1>data-turbolinks-eval=false script</h1>
<script data-turbolinks-eval="false">
<h1>data-turbo-eval=false script</h1>
<script data-turbo-eval="false">
if ("bodyScriptEvaluationCount" in window) {
window.bodyScriptEvaluationCount++
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Form</title>
<script src="/fixtures/turbolinks.js" data-turbolinks-track="reload"></script>
<script src="/fixtures/turbo.js" data-turbo-track="reload"></script>
<script src="/fixtures/test.js"></script>
</head>
<body>
Expand Down
Loading

0 comments on commit 0fa64b0

Please sign in to comment.