Skip to content

Requests

Interfaces

Visit()

Visit(input: string, options: VisitProps): Promise\<Meta>

Use visit to make single page transitions from one page. The function is a wrapper around fetch and made to mimic a link click or a form submision. When used, a json request will be made for the next page, then Superglue saves the response, swap the page component, and change the browser history.

Note

There can be only one visit at a time. If another visit is called from elsewhere, the previous visit would be aborted.

You must provide the implentation and pass it back to Superglue in application.js. Superglue will then pass it to your page components and use it for UJS navigation. This is usually generated for you in application_visit.js where you can customize its behavior globally.

Parameters

Parameter Type Description
input string The first argument to Fetch
options VisitProps

Returns

Promise\<Meta>

Defined in

lib/types/requests.ts:22


VisitProps

Options for Visit

Extends

  • BaseProps

Properties

Property Type Description Inherited from Defined in
placeholderKey? string When present, Superglue will use the page state located at that pageKey and optimistally navigates to it as the next page's state while the requests resolves. - lib/types/requests.ts:36
revisit? boolean When true and the request method is a GET, changes the suggestionAction of the Meta object to none so that Superglue does nothing to window.history. When the GET response was redirected, changes suggestedAction to replace - lib/types/requests.ts:43
method? string The HTTP method BaseProps.method lib/types/requests.ts:67
body? BodyInit The HTTP body BaseProps.body lib/types/requests.ts:69
headers? {} The HTTP headers BaseProps.headers lib/types/requests.ts:71
beforeSave? BeforeSave - BaseProps.beforeSave lib/types/requests.ts:74

Remote()

Remote(input: string, options: RemoteProps): Promise\<Meta>

Remote is is wrapper around fetch. Its used to make a request and mutate the store. Remote does not navigate, and it does not change the browser history. There can be multiple Remote requests running concurrently.

This function is to be built, customized, and returned to superglue by the developer. This is usually generated as application_visit.js where you can make minimum edits to affect its global usage.

Parameters

Parameter Type Description
input string The first argument to Fetch
options RemoteProps The fetch RequestInit with additional options

Returns

Promise\<Meta>

Defined in

lib/types/requests.ts:59


RemoteProps

Options for Visit

Extends

  • BaseProps

Properties

Property Type Description Inherited from Defined in
method? string The HTTP method BaseProps.method lib/types/requests.ts:67
body? BodyInit The HTTP body BaseProps.body lib/types/requests.ts:69
headers? {} The HTTP headers BaseProps.headers lib/types/requests.ts:71
beforeSave? BeforeSave - BaseProps.beforeSave lib/types/requests.ts:74
pageKey? string Specifies where to store the remote payload, if not provided Remote will use the currentPageKey at SuperglueState - lib/types/requests.ts:85

BeforeSave()

BeforeSave(prevPage: VisitResponse, receivedPage: VisitResponse): VisitResponse

A callback that will be fire in between recieving a payload and saving a payload. Use this callback to modify the payload before it gets saved. Its useful for appending, prepending, shuffeling, etc. recieved data to existing data.

const beforeSave = (prevPage, nextPage) => {
  nextPage.data.messages = [
    prevPage.data.messages,
    ... nextPage.data.messages
  ]

  return nextPage
}

remote("/posts", {beforeSave})

Parameters

Parameter Type
prevPage VisitResponse
receivedPage VisitResponse

Returns

VisitResponse

Defined in

lib/types/requests.ts:108