npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backstack

v1.3.0

Published

Animated, stateful and simple single page app functionality for use with Cordova.

Downloads

19

Readme

Published on webcomponents.org

Backstack

Animated, stateful, and simple single page app functionality for use with Cordova.

This component includes the ability to save and restore state. This is important for Cordova Android apps which may get shutdown in the background. This component allows the app to restore the screen history when the app is reloaded. Other SPA and router frameworks that rely on the built in browser history lose that history after the app is reloaded.

Live Demo @ backstack.netlify.com

API Documentation

Installation

This assumes it will be bundled in a larger package using webapp, rollup, or another bundler. It requires LitElement to be available as a peer dependency. No polyfills included.

npm install --save backstack

Usage

<backstack-manager id="myApp"></backstack-manager>

Set the screen factory property in JavaScript. Optionally set the transition property as well for the default transition.

import {ScreenTransition} from 'backstack';

const nav = document.getElementById('myApp');

// see screen factory function section for more details
nav.screenFactory = (id, state, container)=>{
  return {getState:function() {}}; 
}

Navigator Functionality

These examples show basic usage. Consult the API documentation for more details.

transition

Set the default transition to use. Individual operations can override this in options.

nav.transition = ScreenTransition.SlideLeft;

push(id, state, [options])

Show new screen. Save the history of previous screens.

nav.push('simple-screen', {counter:5});

set(id, state, [options])

Show the new screen and clear out all screen history.

nav.set('simple-screen', {counter:5});

back()

Hide the current screen and show the previous screen in the history.

nav.back()

getState() and setState()

Saving and restoring state.

const state = nav.getState();
nav.setState(state);

Screen Factory Function

You must implement a function to provide the contents of your screens to the navigator. This function has two responsiblities:

  • Populate the HTMLElement container with the contents of the screen represented by state and id.
  • Provide callbacks for getting the current state of the screen and other lifecycle operations.

The return value is an object with at least one function, getState. This is the function should return any state that needs to be saved for the screen that was just created.

You can also include a disconnect function if you need to do cleanup when the screen is removed.

const e = document.getElementById('myApp');
e.screenFactory = function(id, state, container) {
  switch(id) {
    case 'home':
      // add elements to container to represent home 
      // in the given state
    case 'other-screen':
      // add elements to container to represent 
      // other-screen in the given state

    return {
      getState: function() {
        // function that returns a memento object 
        // for the screen you just populated
      }
      disconnect: function() {
        // called when the elements are about to 
        // be removed from the DOM
      }
    }
  }
}