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

ok-store

v1.0.0

Published

A set of classes for providing store/model for web.

Downloads

2

Readme

ok-store

Build Status

ABOUT ok-store

This is a set of TypeScript/JavaScript classes that provides observable object as the Store. The Store here is used for what we call Model(of MVC, MVVM), State and/or Store(of Flux, Redux) in the context of web applications. An instance of its Store class can keep states of view, and handle changes of them.

INSTALL

$ npm install ok-store

USAGE (TypeScript)

Create a Store

First of all you define a state as an instance of ok.State, and create a store as an instance of ok.Store .

The state includes Items instance. Items instance is an associative array that keeps state of the Store. Items instance is variable by Updators, observable by Publishers, and referable by Getters method in the Store.

/* ExampleStore.ts */

import * as ok from "ok-store";

/* STATE */
class Items {
	public a: string = 'a';
	public b: number = 0;
	public c = {
		a: 'ca',
		b: 1,
		c: {
			a: 'cca',
			b: 1,
		},
	};
}
let state = new ok.State(new Items());

/* STORE */
class Updators {
	public a = state.createUpdator<{a: string}>((i, u) => { i.a = u.a; });
}
class Publishers {
	public a = state.createPublisher<{a: string}>((i) => ({ a: i.a }));
}
class Getters {
	public a = state.createGetter<{a: string}>((i) => ({ a: i.a }));
}

export default const store = new ok.Store(
    state, new Updators(), new Publishers(), new Getters(),
);

Use the Store

store.getters can get current parameter of the Store. Each getters methods will get transformed objects from the original Items by the store definition above. So you can get suitable value for each view or other communications.

/* ExampleApp1.ts */

import store from "./ExampleStore";

let a: string = store.getters.a().a;

console.log(a); // => 'a'

store.updators can update the Store. Each updators methods require certain object argument by the store definition (just like payload of Redux Action).

/* ExampleApp2.ts */

import store from "./ExampleStore";

let a: string;

store.updators.a(() => ({ a: 'changed' }));
a = store.getters.a().a;

console.log(a); // => 'changed'

store.publishers can call functions when the Store is updated. Each publishers methods can refer certain object transformed from the store items by function argument.

/* ExampleApp3.ts */

import store from "./ExampleStore";

let a: string;
let cnt: number = 0;

store.publishers.a((p) => {
    a = p.a;
    if (cnt === 0) {
        console.log(a); // => 'a'
    } else if (cnt === 1) {
        console.log(a); // => 'changed'
    }
    cnt++;
});

store.updators.a(() => ({ a: 'changed' }));

By setting a view rendering method (like ReactDOM.render) in publishers, you can use the store as a data bindings utility.

DEVELOP

$ npm install
$ npm run build:main

TEST

$ npm test