Skip to content
Annotate fields to be persisted on navigation away from the current page
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test reference bundle in parent folder Feb 22, 2019
.eslintrc.json
.flowconfig
.gitignore
.travis.yml
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Feb 18, 2019
CONTRIBUTING.md
LICENSE Initial commit Feb 6, 2019
README.md
package-lock.json
package.json
prettier.config.js
rollup.config.js run prettier Feb 21, 2019
session-resume.js
session-resume.js.flow

README.md

Session Resume

Annotate fields to be persisted on navigation away from the current page. Fields be automatically restored when the user revists the page again in their current browser session (excludes separate tabs).

Not design for persisted crash recovery.

Installation

$ npm install @github/session-resume

Usage

HTML

<form>
  <input id="new-comment" class="js-session-resumable"/>
</form>

JS

import {persistResumableFields, restoreResumableFields, setForm} from '@github/session-resume'

function getPageID() {
  return window.location.pathname
}

// Listen for all form submit events and to see if their default submission
// behavior is invoked.
window.addEventListener('submit', setForm, {capture: true})

// Resume field content on regular page loads.
window.addEventListener('pageshow', function() {
  restoreResumableFields(getPageID())
})

// Persist resumable fields when page is unloaded
window.addEventListener('pagehide', function() {
  persistResumableFields(getPageID())
})

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

You can’t perform that action at this time.