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

mimstate

v0.1.1

Published

Persist view state beyond component life-cycle.

Downloads

4

Readme

Mimstate: Persist view state beyond component life-cycle.

JavaScript components almost necessarily use state variables to remember parameter values that determine the aspects of component layout, e.g. whether an item is displayed or hidden. This kind of state is usually referred to as "view state" in order to distinguish it from the "data state", on which the component operates. While the data state initial value is usually provided to the component in properties, the view state is normally internal to the component. Moreover, while the data state exists outside of the component (before the component is created and/or after the component is destroyed), the view state is only created when the component is created and vanishes when the component is destroyed.

Consider an example of a fictitious ToDoItem component, which has a title, a date and a description. The component always displays the title and the date while the description can be shown or hidden when the user clicks a small button. In this simple case, the title, date and description are pieces of the data state while the flag whether the description is hidden is a view state.

The problem arises when there is a need to remember the view state across different instances of the component. For example, if the user clicks the button on the ToDoItem component to show the description, then navigates to a different page and then navigates back to this item, it would be much more user-friendly to show the description right away instead of displaying it hidden and forcing the user to click the button again to reveal it. That is, there is a need to persist the view state beyond the normal life-cycle of the component.

The usual solution to the above problem is to use either session or local storage to keep the latest values of the view state variables. When the component is mounted, the value is read form the storage and (if exists) is used as an initial state value. Every time the state value changes, the new value is written to the storage. Although, this is a simple process, it requires from the developers to write quite a lot of boilerplate code.

Mimstate is a small library that implements this boilerplate code and provides to the developers an easy-to-use and clean API - both imperative and declarative.