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

store-and-pubsub

v1.1.1

Published

Library to store values in user defined paths, also can be subscribed to store published changes through pub sub flow

Downloads

11

Readme

What is this?

A simple library to manage a Store and subscriptions to store values.

How to use it?

First you need to import it in your project

The require way

let { pullFrom, pushTo } = require("store-and-pubsub");

The import way

import { unsetPath } from "store-and-pubsub";

Then use it to establish a store with getter and setter for a path, for example currentParam

import { pullFrom, pushTo } from "store-and-pubsub";

const MODULE_STORE_NAME = 'moduleStoreName'

// INITIALIZE AN EMPTY STORE FOR YOUR MODULE
pushTo(MODULE_STORE_NAME, {})

// CREATE A SETTER FOR SOME PATH TO STORE
pushTo(`${MODULE_STORE_NAME}.currentParam`, state)

// CREATE A GETTER FOR SOME PATH TO RETRIEVE
pullFrom(`${MODULE_STORE_NAME}.currentParam`)

To unset or push multiple values to store

import { unsetPath, pushValuesTo } from "store-and-pubsub";

const MODULE_STORE_NAME = 'moduleStoreName'

// REMOVES THE PROPERTY AT PATH OF STORE
unsetPath(`${MODULE_STORE_NAME}.currentParam`)

// PUSHES MULTIPLE PROPERTIES AND VALUES AT PATH OF STORE
const values = {
  prop1: "value1",
  prop2: "value2",
}
pushValuesTo(`${MODULE_STORE_NAME}`, values)

Paths from store can be subscribed for changes

import { subscribeToPath, unsubscribeFromPath, removeSubscription } from "store-and-pubsub";

const MODULE_STORE_NAME = 'moduleStoreName'

const path = `${MODULE_STORE_NAME}.currentParam`

const myCallback = () => {
  // YOUR OWN CODE AND STUFF
}

// SUBSCRIBES TO moduleStoreName.currentParam CHANGES EXECUTING myCallback
const subscriber = subscribeToPath(path, myCallback)

// REMOVES SUBSCRIPTION FRM GIVEN PATH
unsubscribeFromPath(path)

// GIVEN subscriber REMOVES IT FROM PATH SUBSCRIPTION
removeSubscription(subscription)

// GIVEN myCallback REMOVES IT FROM ALL PATHS SUBSCRIBED
removeSubscription(myCallback)

Powered by xiscodev

JSDOC

Table of Contents

pullFrom

Retrieves value from stored path.

Type: Function

Parameters
  • path string locator string path to store

Returns any can be anything stored at given path, anythng stored returns undefined

pushTo

Push value to path and notify if could publish.

Type: Function

Parameters
  • path string locator string path to store
  • newValue any the value to push
  • forceUpdate (optional, default false)

pushValuesTo

Push value to path.

Type: Function

Parameters
  • path string locator string path to store
  • values object contains multiple keys and values to be pushed to store

unsetPath

Removes path stored.

Type: Function

Parameters
  • path string locator string path to store

Returns boolean true if unset has been effective, otherwise returns false

subscribeToPath

Subscribes to stored path changes with given callback.

Type: Function

Parameters
  • path string locator string path to store
  • callback

Returns any reference to be used to single unsubscribe

unsubscribeFromPath

Unsubscribe from given paths were has subscribed.

Type: Function

Parameters
  • path string locator string path to store

removeSubscription

Unsubscribe from all paths were callback or subscriber has subscribed.

Type: Function

Parameters