-
Notifications
You must be signed in to change notification settings - Fork 421
/
index.js
124 lines (112 loc) · 3.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { Session } from "./session"
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 { fetch, recentRequests } from "../http/fetch"
const session = new Session(recentRequests)
const { cache, navigator } = session
export { navigator, session, cache, PageRenderer, PageSnapshot, FrameRenderer, fetch }
/**
* Starts the main session.
* This initialises any necessary observers such as those to monitor
* link interactions.
*/
export function start() {
session.start()
}
/**
* Registers an adapter for the main session.
*
* @param adapter Adapter to register
*/
export function registerAdapter(adapter) {
session.registerAdapter(adapter)
}
/**
* Performs an application visit to the given location.
*
* @param location Location to visit (a URL or path)
* @param options Options to apply
* @param options.action Type of history navigation to apply ("restore",
* "replace" or "advance")
* @param options.historyChanged Specifies whether the browser history has
* already been changed for this visit or not
* @param options.referrer Specifies the referrer of this visit such that
* navigations to the same page will not result in a new history entry.
* @param options.snapshotHTML Cached snapshot to render
* @param options.response Response of the specified location
*/
export function visit(location, options) {
session.visit(location, options)
}
/**
* Connects a stream source to the main session.
*
* @param source Stream source to connect
*/
export function connectStreamSource(source) {
session.connectStreamSource(source)
}
/**
* Disconnects a stream source from the main session.
*
* @param source Stream source to disconnect
*/
export function disconnectStreamSource(source) {
session.disconnectStreamSource(source)
}
/**
* Renders a stream message to the main session by appending it to the
* current document.
*
* @param message Message to render
*/
export function renderStreamMessage(message) {
session.renderStreamMessage(message)
}
/**
* Removes all entries from the Turbo Drive page cache.
* Call this when state has changed on the server that may affect cached pages.
*
* @deprecated since version 7.2.0 in favor of `Turbo.cache.clear()`
*/
export function clearCache() {
console.warn(
"Please replace `Turbo.clearCache()` with `Turbo.cache.clear()`. The top-level function is deprecated and will be removed in a future version of Turbo.`"
)
session.clearCache()
}
/**
* Sets the delay after which the progress bar will appear during navigation.
*
* The progress bar appears after 500ms by default.
*
* Note that this method has no effect when used with the iOS or Android
* adapters.
*
* @param delay Time to delay in milliseconds
*/
export function setProgressBarDelay(delay) {
session.setProgressBarDelay(delay)
}
export function setConfirmMethod(confirmMethod) {
FormSubmission.confirmMethod = confirmMethod
}
export function setFormMode(mode) {
session.setFormMode(mode)
}
/**
* Allows to define additional logic to prevent prefetching of links.
*
* By default Turbo includes a check for compatibility with older apps to prevent
* prefetching unsafe UJS links, such as those that include data-remote, data-behavior,
* data-method or data-confirm attributes, but you can override this behavior by
* providing your own check.
*
* @param checkFn Function that returns a boolean value to indicate whether
* prefetching should be prevented or not
*/
export function preventLinkPrefetch(checkFn) {
session.linkPrefetchObserver.preventLinkPrefetch = checkFn
}