Breezy
main
main
  • README
  • Code of conduct
  • Contributing Guide
  • Changelog
  • Security Policy
  • docs
    • configuration
    • Cross cutting concerns
    • deferments
    • Demo Application
    • Digging
    • Overview
    • Installation
    • NavigationContext
    • The page response
    • Rails utils
    • The store shape
    • Requests
    • Tutorial
    • The return of Rails UJS
    • recipes
      • Infinite scroll
      • Modals
      • progress-bar
      • Shopping cart
      • SPA (Single Page Application) Pagination
      • Server-Side Rendering
      • Replicating Turbo behavior
      • Usage with vite
    • Modules
      • Functions
      • Functions
      • index
      • types.actions
      • types
      • Interfaces
Powered by GitBook
On this page
  • References
  • Interfaces
  • Type Aliases

Was this helpful?

  1. docs
  2. Modules

types

Previoustypes.actionsNextInterfaces

Last updated 4 months ago

Was this helpful?

References

FetchArgs

Re-exports

GraftingSuccessAction

Re-exports

GraftingErrorAction

Re-exports

Visit

Re-exports

VisitProps

Re-exports

Remote

Re-exports

RemoteProps

BeforeSave

ApplicationRemote

ApplicationVisit

Interfaces

ParsedResponse

Properties

Property
Type
Defined in

rsp

Response

json


Defer

Defer is a node in the page response thats been intentionally filled with empty or placeholder data for the purposes of fetching it later.

You would typically use it with props_template for parts of a page that you know would be slower to load.

Properties

Property
Type
Description
Defined in

url

string

A url with props_at keypath in the query parameter to indicate how to dig for the data, and where to place the data.

type

"auto" | "manual"

When set to auto Superglue will automatically make the request using the url. When set to manual, Superglue does nothing, and you would need to manually use remote with the url to fetch the missing data.

path

string

A keypath indicates how to dig for the data and where to place the data.

successAction

string

a user defined action for Superglue to dispatch when auto deferement is successful

failAction

string

a user defined action for Superglue to dispatch when auto deferement failed


GraftResponse<T>

The GraftResponse is a protocol, a shape that is responsible for partial updates using props_template's digging functionality in Superglue. Its meant to be implemented by the server and if you are using superglue_rails, the generators would have generated a props_template layout and view that would shape the graft responses for you.

Type Parameters

Type Parameter
Default type

T

Properties

Property
Type
Description
Defined in

data

T

-

componentIdentifier

string

-

assets

string[]

-

csrfToken?

string

-

fragments

-

defers

-

slices

-

renderedAt

number

-

restoreStrategy

-

action

"graft"

-

path

string

Used by superglue to replace the data at that location.


Fragment

A Fragment identifies a cross cutting concern, like a shared header or footer.

Properties

Property
Type
Description
Defined in

type

string

path

string

A Keypath specifying the location of the fragment


SuperglueState

A read only state that contains meta information about the current page.

Properties

Property
Type
Description
Defined in

currentPageKey

string

search

Record<string, undefined | string>

The query string object of the current url.

csrfToken?

string

The Rails csrfToken that you can use for forms.

assets

string[]

The tracked asset digests.


RootState<T>

The root state for a Superglue application. It occupies 2 keys in your app.

Type Parameters

Type Parameter
Default type

T

Indexable

[name: string]: unknown

Properties

Property
Type
Description
Defined in

superglue

Contains readonly metadata about the current page

pages


Meta

Meta is passed to the Promise when visit or remote resolves and contains additional information for navigation.

Extended by

Properties

Property
Type
Description
Defined in

pageKey

string

page

redirected

boolean

Indicates if response was redirected

rsp

Response

The original response object

fetchArgs

The original args passed to fetch.

componentIdentifier

string

needsRefresh

boolean

true when assets locally are detected to be out of date


VisitMeta

Meta is passed to the Promise when visit or remote resolves and contains additional information for navigation.

Extends

Properties

Property
Type
Description
Inherited from
Defined in

pageKey

string

page

redirected

boolean

Indicates if response was redirected

rsp

Response

The original response object

fetchArgs

The original args passed to fetch.

componentIdentifier

string

needsRefresh

boolean

true when assets locally are detected to be out of date

navigationAction

-


Handlers

Properties

Property
Type
Defined in

onClick

(event: MouseEvent<HTMLDivElement, MouseEvent>) => void

onSubmit

(event: FormEvent<HTMLDivElement>) => void


HistoryState

The state that is saved to history.state. Superglue stores information about the current page so that it can restore the page state when navigating back

Properties

Property
Type
Description
Defined in

superglue

true

Is always true so superglue can differentiate pages that have superglue enabled or not

pageKey

string

posX

number

The scroll position X of the page

posY

number

The scroll position Y of the page


BasicRequestInit

A variation of RequestInit except the headers must be a regular object

Extends

  • RequestInit

Properties

Property
Type
Description
Overrides
Defined in

headers?

{}

A Headers object, an object literal, or an array of two-item arrays to set request's headers.

RequestInit.headers


NavigationContextProps

You can also use this to build your own <Link> component.

Properties

Property
Type
Description
Defined in

navigateTo

-

visit

-

remote

-

pageKey

string

search

Record<string, undefined | string>

The current pageKey (current url) query params as an object.


NavigationProviderProps

Properties

Property
Type
Description
Defined in

history

History

-

visit

-

remote

-

mapping

Record<string, ComponentType<{}>>

-

initialPageKey

string


BuildStore()

Parameters

Parameter
Type
Description

initialState

A preconfigured intial state to pass to your store.

reducer

object

A preconfigured reducer

reducer.superglue

-

reducer.pages

-

Returns

Defined in


BuildVisitAndRemote()

Parameters

Parameter
Type
Description

navigatorRef

store

Returns

Name
Type
Defined in

visit

remote

Defined in


SetupProps

Properties

Property
Type
Description
Defined in

initialPage

The global var SUPERGLUE_INITIAL_PAGE_STATE is set by your erb template, e.g., index.html.erb

baseUrl

string

The base url prefixed to all calls made by visit and remote.

path

string

The path of the current page. It should equal to the location.pathname + location.search + location.hash

store

The exported store from store.js. If you used the generators it would contain slices for superglue, pages, and the flash.

buildVisitAndRemote

A factory function that will return a visit and remote function. All of Superglue and UJS will use these functions. You should customize the function, for example, to add a progress bar.

history?

History

An optional history object https://github.com/remix-run/history. If none is provided Superglue will create one for you.

navigatorRef

A ref object created from the Application component that will be passed to buildVisitAndRemote


ApplicationProps

Props for the Application component

Extends

  • ComponentPropsWithoutRef<"div">

Properties

Property
Type
Description
Defined in

initialPage

The global var SUPERGLUE_INITIAL_PAGE_STATE is set by your erb template, e.g., index.html.erb

baseUrl

string

The base url prefixed to all calls made by visit and remote.

path

string

The path of the current page. It should equal to the location.pathname + location.search + location.hash

buildVisitAndRemote

A factory function that will return a visit and remote function. All of Superglue and UJS will use these functions. You should customize the function, for example, to add a progress bar.

mapping

Record<string, ComponentType<{}>>

A mapping between your page props and page component. This is setup for you in page_to_page_mapping.

history?

History

An optional history object https://github.com/remix-run/history. If none is provided Superglue will create one for you.

store

The exported store from store.js. If you used the generators it would contain slices for superglue, pages, and the flash.

Type Aliases

PageKey

PageKey: string

A PageKey is a combination of a parsed URL's pathname + query string. No hash.

Example

/posts?foobar=123

Defined in


RestoreStrategy

RestoreStrategy: "fromCacheOnly" | "revisitOnly" | "fromCacheAndRevisitInBackground"

Defines the behavior when navigating to a page that is already stored on the client. For example, when navigating back.

When the page already exists in the store:

  • fromCacheOnly - Use the cached page that exists on the store, only.

  • fromCacheAndRevisitInBackground - Use the cache version of the page so superglue can optimistically navigate to it, then make an additional request for the latest version.

Defined in


NavigationAction

NavigationAction: "push" | "replace" | "none"

A NavigationAction is used to tell Superglue to history.push, history.replace or do nothing.

Defined in


ComponentIdentifier

ComponentIdentifier: string

An identifier that Superglue will uses to determine which page component to render with your page response.

Defined in


Keypath

Keypath: string

A keypath is a string representing the location of a piece of data. Superglue uses the keypath to dig for or update data.

Examples

Object access

data.header.avatar

Array access

data.body.posts.0.title

Array with lookahead

data.body.posts.post_id=foobar.title

Defined in


JSONPrimitive

JSONPrimitive: string | number | boolean | null | undefined

A JSON Primitive value

Defined in


JSONObject

JSONObject: {}

A JSON Object

Index Signature

Defined in


JSONMappable

A JSON Object or an array of values

Defined in


JSONKeyable

A array of JSON key value objects or a JSON Object

Defined in


JSONValue

A primitive or a mappable object

Defined in


VisitResponse<T>

The VisitResponse is a protocol, a shape that is responsible for full page visits in Superglue. Its meant to be implemented by the server and if you are using superglue_rails, the generators would have generated a props_template layout and view that would shape the visit responses for you.

Type Parameters

Type Parameter
Default type

T

Type declaration

Name
Type
Defined in

data

T

componentIdentifier

assets

string[]

csrfToken?

string

fragments

defers

slices

renderedAt

number

restoreStrategy

Defined in


Page<T>

A Page is a VisitResponse that's been saved to the store

Type declaration

Name
Type
Defined in

savedAt

number

Type Parameters

Type Parameter
Default type

T

Defined in


PageResponse

Defined in


AllPages<T>

The store where all page responses are stored indexed by PageKey. You are encouraged to mutate the Pages in this store.

Type Parameters

Type Parameter
Default type

T

Defined in


VisitCreator()

Parameters

Parameter
Type

input

options

Returns

Defined in


RemoteCreator()

Parameters

Parameter
Type

input

options

Returns

Defined in


Dispatch

Defined in


SuperglueStore

A Store created with Redux Toolkit's configureStore setup with reducers from Superglue. If you are using superglue_rails this would have been generated for you in store.js and setup correctly in application.js

Defined in


UJSHandlers()

Parameters

Parameter
Type

{ ujsAttributePrefix, visit, remote, store, }

object

{ ujsAttributePrefix, visit, remote, store, }.ujsAttributePrefix

string

{ ujsAttributePrefix, visit, remote, store, }.visit

{ ujsAttributePrefix, visit, remote, store, }.remote

{ ujsAttributePrefix, visit, remote, store, }.store

Returns

Defined in


SaveAndProcessPageThunk

Defined in


MetaThunk

Defined in


VisitMetaThunk

Defined in


DefermentThunk

Defined in


NavigateTo()

Passed to every page component and also available as part of a NavigationContext:

import { NavigationContext } from '@thoughtbot/superglue';

const { navigateTo } = useContext(NavigationContext)

If there is an existing page in your store navigateTo will restore the props, render the correct component, and return true. Otherwise, it will return false. This is useful if you want to restore an existing page before making a call to visit or remote.

Parameters

Parameter
Type
Description

path

options

object

-

options.action

when none, navigateTo will immediately return false

Returns

boolean

true if the navigation was a success, false if the page was not found in the store.

Defined in

Re-exports

Re-exports

Re-exports

Re-exports

[]

[]

A user supplied string identifying a fragment. This is usually created using

The (url pathname + search) of the current page. This can be pass to .

<T>

Every that superglue recieves is stored here.

The URL of the response converted to a pageKey. Superglue uses this to persist the to store, when that happens.

<>

The of the page

The extracted from the response.

The URL of the response converted to a pageKey. Superglue uses this to persist the to store, when that happens.

.

<>

The of the page

.

.

.

.

The extracted from the response.

.

.

The . This can be used for navigation.

The page key in to restore from

Superglue comes with a Navigation component that provides a context with access to , and other useful tooling.

The pagekey that's being used to render the current page component. Useful when used in combination with to create requests that target the current page.

This is the navigation component that gets used by . The component takes a mapping of page components and swaps them when navigating and passes to all page components.

The that's to be used when first rendering. Used to determine the initial page component to show.

Provide this callback to returning a Redux store for Superglue to use. This would be setup and generated for you in store.js. We recommend using using Redux toolkit's configureStore to build the store.

BuildStore(initialState: <>, reducer: {superglue: superglueReducer;pages: pageReducer; }):

Provide this callback to returning a Redux store for Superglue to use. This would be setup and generated for you in store.js. We recommend using using Redux toolkit's configureStore to build the store.

<>

(state: , action: Action) =>

(state: , action: Action) =>

Provide this callback to returning a visit and remote function. These functions will be used by Superglue to power its UJS attributes and passed to your page components and . You may customize this functionality to your liking, e.g, adding a progress bar.

BuildVisitAndRemote(navigatorRef: RefObject<null | {navigateTo: ; }>, store: ): {visit: ;remote: ; }

Provide this callback to returning a visit and remote function. These functions will be used by Superglue to power its UJS attributes and passed to your page components and . You may customize this functionality to your liking, e.g, adding a progress bar.

RefObject<null | {navigateTo: ; }>

{visit: ;remote: ; }

<>

RefObject<null | {navigateTo: ; }>

<>

revisitOnly - Ignore the cache and make a request for the latest page. If the response was 200, the would be none as we don't want to push into history. If the response was redirected, the would be set to replace.

[key: string]:

JSONMappable: [] |

JSONKeyable: [] |

JSONValue: |

VisitResponse<T>: {data: T;componentIdentifier: ;assets: string[];csrfToken: string;fragments: [];defers: [];slices: ;renderedAt: number;restoreStrategy: ; }

[]

[]

Page<T>: <T> & {savedAt: number; }

PageResponse: |

A PageResponse can be either a or a . Its meant to be implemented by the server and if you are using superglue_rails, the generators will handle both cases.

AllPages<T>: Record<, <T>>

VisitCreator: (input: string | , options: ) =>

VisitCreator is a Redux action creator that returns a thunk. Use this to build the function. Typically its already generated in application_visit.js

string |

RemoteCreator: (input: string | , options: ) =>

RemoteCreator is a Redux action creator that returns a thunk. Use this to build the function. Typically its already generated in application_visit.js

string |

Dispatch: ThunkDispatch<, undefined, Action>

SuperglueStore: EnhancedStore<, Action, Tuple<[StoreEnhancer<{dispatch: ; }>, StoreEnhancer]>>

UJSHandlers: ({ ujsAttributePrefix, visit, remote, store, }: {ujsAttributePrefix: string;visit: ;remote: ;store: ; }) =>

SaveAndProcessPageThunk: ThunkAction<Promise<void>, , undefined, Action>

MetaThunk: ThunkAction<Promise<>, , undefined, Action>

VisitMetaThunk: ThunkAction<Promise<>, , undefined, Action>

DefermentThunk: ThunkAction<Promise<void[]>, , undefined, Action>

NavigateTo: (path: , options: {action: ; }) => boolean

Manually navigate using pages that exists in the store and restores scroll position. navigateTo is what in your application_visit.js ultimately calls.

lib/types/index.ts:447
lib/types/index.ts:463
lib/types/index.ts:22
lib/types/index.ts:38
lib/types/index.ts:47
lib/types/index.ts:53
lib/types/index.ts:77
lib/types/index.ts:84
lib/types/index.ts:89
lib/types/index.ts:96
lib/types/index.ts:101
lib/types/index.ts:106
lib/types/index.ts:150
lib/types/index.ts:166
lib/types/index.ts:191
lib/types/index.ts:209
lib/types/index.ts:274
lib/types/index.ts:283
lib/types/index.ts:288
lib/types/index.ts:295
lib/types/index.ts:313
lib/types/index.ts:341
lib/types/index.ts:348
lib/types/index.ts:349
lib/types/index.ts:356
lib/types/index.ts:394
VisitMeta
Meta
ApplicationProps
NavigateTo
ApplicationProps
RootState
JSONMappable
SuperglueStore
ApplicationProps
SuperglueStore
ApplicationProps
NavigationContextProps
ApplicationProps
NavigationContextProps
NavigationAction
NavigationAction
JSONValue
JSONValue
JSONObject
JSONObject
JSONObject
JSONPrimitive
JSONMappable
ComponentIdentifier
Fragment
Defer
JSONObject
RestoreStrategy
VisitResponse
GraftResponse
VisitResponse
GraftResponse
VisitResponse
PageKey
Page
VisitMetaThunk
MetaThunk
RootState
RootState
Dispatch
Handlers
RootState
Meta
RootState
VisitMeta
RootState
RootState
Keypath
NavigationAction
lib/types/index.ts:111
lib/types/index.ts:112
lib/types/index.ts:137
lib/types/index.ts:138
lib/types/index.ts:139
lib/types/index.ts:140
lib/types/index.ts:141
lib/types/index.ts:151
lib/types/index.ts:152
lib/types/index.ts:153
lib/types/index.ts:154
lib/types/index.ts:155
lib/types/index.ts:156
lib/types/index.ts:157
lib/types/index.ts:159
lib/types/index.ts:160
lib/types/index.ts:182
lib/types/index.ts:183
props_template
lib/types/index.ts:201
lib/types/index.ts:202
lib/types/index.ts:217
lib/types/index.ts:219
lib/types/index.ts:221
lib/types/index.ts:223
lib/types/index.ts:232
lib/types/index.ts:234
lib/types/index.ts:248
lib/types/index.ts:250
lib/types/index.ts:252
lib/types/index.ts:254
lib/types/index.ts:256
lib/types/index.ts:258
lib/types/index.ts:260
lib/types/index.ts:248
lib/types/index.ts:250
lib/types/index.ts:252
lib/types/index.ts:254
lib/types/index.ts:256
lib/types/index.ts:258
lib/types/index.ts:260
lib/types/index.ts:265
lib/types/index.ts:309
lib/types/index.ts:310
lib/types/index.ts:332
lib/types/index.ts:334
lib/types/index.ts:336
lib/types/index.ts:338
lib/types/index.ts:365
lib/types/index.ts:414
lib/types/index.ts:415
lib/types/index.ts:416
lib/types/index.ts:417
lib/types/index.ts:418
lib/types/index.ts:431
lib/types/index.ts:432
lib/types/index.ts:433
lib/types/index.ts:434
lib/types/index.ts:435
lib/types/index.ts:467
lib/types/index.ts:468
lib/types/index.ts:477
lib/types/index.ts:482
lib/types/index.ts:487
lib/types/index.ts:492
lib/types/index.ts:499
lib/types/index.ts:504
lib/types/index.ts:508
lib/types/index.ts:522
lib/types/index.ts:527
lib/types/index.ts:532
lib/types/index.ts:539
lib/types/index.ts:544
lib/types/index.ts:549
lib/types/index.ts:554
lib/types/index.ts:151
lib/types/index.ts:152
lib/types/index.ts:153
lib/types/index.ts:154
lib/types/index.ts:155
lib/types/index.ts:156
lib/types/index.ts:157
lib/types/index.ts:159
lib/types/index.ts:160
lib/types/index.ts:167
PageResponse
JSONMappable
Fragment
Defer
JSONObject
RestoreStrategy
JSONMappable
SuperglueState
AllPages
PageResponse
VisitResponse
VisitResponse
JSONMappable
VisitResponse
ComponentIdentifier
VisitResponse
Meta
pageKey
VisitResponse
JSONMappable
VisitResponse
Meta
page
Meta
redirected
Meta
rsp
Meta
fetchArgs
ComponentIdentifier
Meta
componentIdentifier
Meta
needsRefresh
NavigationAction
NavigationAction
SuperglueState
NavigateTo
PageKey
RootState
JSONMappable
SuperglueState
SuperglueState
AllPages
AllPages
NavigateTo
SuperglueStore
VisitResponse
JSONMappable
SuperglueStore
BuildVisitAndRemote
NavigateTo
VisitResponse
JSONMappable
BuildVisitAndRemote
SuperglueStore
JSONMappable
ComponentIdentifier
Fragment
Defer
JSONObject
RestoreStrategy
JSONMappable
JSONMappable
PageKey
PageKey
SuperglueStore
Keypath
NavigationAction
NavigateTo
SuperglueStore
PageKey
VisitMetaThunk
PageKey
MetaThunk
SuperglueStore
Handlers
PageKey
FetchArgs
FetchArgs
FetchArgs
GraftingSuccessAction
GraftingErrorAction
Visit
VisitProps
Remote
RemoteProps
BeforeSave
ApplicationRemote
ApplicationVisit
Visit
Remote
ApplicationVisit
ApplicationRemote
ApplicationVisit
ApplicationRemote
VisitProps
Visit
RemoteProps
Remote
ApplicationVisit
ApplicationRemote
Visit
Remote
ApplicationVisit
ApplicationRemote
Remote
ApplicationVisit
ApplicationRemote
ApplicationVisit
ApplicationRemote
VisitProps
RemoteProps
ApplicationVisit
ApplicationRemote