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

@uirouter/sticky-states

v1.5.1

Published

UI-Router Sticky States: Keep states and their components alive while a different state is activated

Downloads

16,345

Readme

Sticky States

Greenkeeper badge

Sticky States for UI-Router 1.0  Build Status

Overview and Use Case

Sticky States allows two or more trees of states to run concurrently along side each other.

The initial use case for this functionality is to implement "tabs" for application modules. Using Sticky States, a single app can implement one state tree for each tab, and have them operate at the same time, in parallel to each other. Each tab is implemented as its own UI-Router state tree. While one tab is active, the other tab is inactivated, but can be reactivated without losing any work in progress.

For the tabs use case, Sticky States work best along with Deep State Redirect

Sticky State Lifecycle

A Sticky State is the root of a UI-Router state tree which can continue running even after it is "exited". The sticky state (and its children) have a different lifecycle than normal states. The views of a Sticky State (and all activated substates) are retained until one of two things happen:

  • The parent of the sticky state is exited
  • The parent of the sticky state is directly activated

If a sibling of the sticky state (or a child of a sibling) is activated, the sticky state tree will "inactivate". A transition back to the inactivate state will reactivate it.

Using

Sticky states works requires ui-router-core 2.0.0 or above. Run npm ls to check the version of ui-router-core included with the UI-Router distribution for your framework

1) Add Plugin

ng1

In Angular 1, register a plugin by injecting $uiRouterProvider in a config() block.

import {StickyStatesPlugin} from "@uirouter/sticky-states";

angular.module('myapp', ['ui.router']).config(function($uiRouterProvider) {
  $uiRouterProvider.plugin(StickyStatesPlugin);
});

ng2

In Angular 2, register a plugin in your UIRouterConfig class

import {StickyStatesPlugin} from "@uirouter/sticky-states";

export class MyConfig {
  configure(uiRouter: UIRouter) {
    uiRouter.plugin(StickyStatesPlugin);
  }
}

react

In React, register a plugin after creating your UIRouterReact instance.

import {StickyStatesPlugin} from "@uirouter/sticky-states";

let router = new UIRouterReact();
router.plugin(StickyStatesPlugin);

Or, if using component bootstrapping, add the plugin in your routerConfig function.

let routerConfig = (router) => router.plugin(StickyStatesPlugin);

return <UIRouterReact config={routerConfig}/>;

2) Mark a state as sticky

The sticky state's view must target a named ui-view. The named ui-view must not be shared with other states.

Create and target a named ui-view.

  <ui-view name="admin"></ui-view>
let adminModule = {
  name: 'admin',
  sticky: true,
  views: {
    admin: { component: AdminComponent }
  }
}

The AdminComponent should remain active in the ui-view named admin, even if a sibling state is activated.

3) Show/Hide the sticky component

When a sticky state is inactive, it's often desired to hide the contents from the UI. This can be achieved using StateService.includes.

In some cases, ui-sref-active may also be used to toggle a class on the named ui-view.

Example

These minimal examples show how to get started with sticky states in:

More

This project was ported from the UI-Router Extras project for legacy UI-Router. For more information, see the ui-router extras documentation: http://christopherthielen.github.io/ui-router-extras/#/sticky

TODO: Rewrite docs