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

web_page_state

v0.0.11

Published

Simple straightforward tool to manage webpage state on the client side and hook state to html tags on page without code

Downloads

1,128

Readme

Page State Helper for client side websites

Utility hooks to help organize a site's client-side state, and easily change the view according to state through html data attributes. Conceptually combines ideas from Bootstrap & Redux.

See published npm package

Import:

  • Web: <script src="https://unpkg.com/page_state/build/bundle.min.js"></script>
  • Node: npm i web_page_state

How to use?

- HTML

| Attribute | Note | Example | |---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | data-ws-show-if | Show element if ANY (ie OR) of the state props specified in the attribute (space separated) is true, otherwise set 'display' style to 'none'. To achieve AND simply nest elements. | - Simple: <button data-ws-show-if="isSignedIn">Sign Out</button> - OR: <div data-ws-show-if="isIOS isAndroid">You are on iOS OR Android</div> - AND: <div data-ws-show-if="isSignedIn"><p data-ws-show-if="isIOS"><Welcome user on iOS</p></div> | | data-ws-show-if-not | Show element if ANY (ie OR) of the NEGATED state props specified in the attribute (space separated) is true, otherwise set 'display' style to 'none' | <button data-ws-show-if-not="isSignedIn">Sign In</button> | | data-ws-label | Replaces the element's innerText with the prop's value | <p>Welcome <span data-ws-label="user.name"></span></p> |

- js

| Property | Type | Description | |---------------------------|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | pageState | Object | Holds the raw state. | | updatePageStateWithParams | Function | Examples: updatePageStateWithParams({countryName: "Brazil"}) | | toastNotification | Function | Example: toastNotification("Copied", "Successfully copied to clipboard", false, false); | | dismissNotification | Function | Remove previously toasted notification | | setUser | Function | Examples:- On sign in: setUser({name: "Ronen", uid: "987dkjbc987"}); - On sign out: setUser(null); | | getParam | Function | getParam("user.uid"); | | toggleParam | Function | toggleParam("isFullScreen"); | | registerListener | Function | Returns the index / id as number of the new listener. This index can be used to remove the listener. Example: let index = PageState.registerListener(function(newState){/* do something */}); PageState.unregisterListener(index); | | unregisterListener | Function | Use the index generated when 'registered'. Example: let index = PageState.registerListener(function(newState){/* do something */}); PageState.unregisterListener(index); |

- State's special keys - do not set directly

// TODO: Prohibit direct setting by mistake?

| Key | Type | |-------------------|-------------------------------------------------------| | user | Object, set with setUser | | isNotification | boolean, semi-automatic: based on 'toastNotification' | | | notificationTitle | boolean, semi-automatic: based on 'toastNotification' | | notificationMsg | boolean, semi-automatic: based on 'toastNotification' | | platform | String, automatic | | isMobile | boolean, automatic | | | isIOS | boolean, automatic | | | isAndroid | boolean, automatic | | | isOffline | boolean, automatic | | isSignedIn | boolean, semi-automatic: based on 'user' |

How to use?

When used in browser:

Place the following at the end of the body tag, and prior to using the wsGlobals.PageState.updateStateWithProps

<script src="https://unpkg.com/page_state/build/bundle.min.js"></script>

No need to initialize - it is initialized in code.

When used in a webpack / other node client-side webpage builder:

Use import or require... // TODO: Do we need to initialize? Check...

Showcases

This is used on the following sites:

TODOs:

  • In data-ws-show-if-not we let the function - if exists - override the property, which is inconsistent with the non-negated data-ws-show-if...
  • Prohibit direct setting of reserved props / functions by mistake?
  • Set/get style to the element's html set style prior to setting it to "none"

How to contribute & publish updates to this package?

  • This package is published both on GitHub and on npmjs.
  • To publish an updated version - simply run npm publish, it will commit & push updates both to github and npm.