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

scribax

v1.0.4

Published

A simple state repository and manager for JavaScript applications

Downloads

50

Readme

scribaX

A simple state repository and manager for JavaScript applications

Why scribaX?

Because we don't need a massive amount of software to address a given request. Sometimes a little piece of code will do the trick.

Goals

  • Data Integrity - A single source of truth (SSOT)
  • Predictability - All the views have access to the same value and type of any given data.
  • Enforced security - Data can only be mutated invoking a known action and not by unknown sources or actions.
  • Easy of use - Subscribe to multiple or single property change in the store and customize how your application responds to data changes.

Components & Data Flow

The data flow is always unidirectional and all shareable data will be persisted in the store.

The only way to update data is by explicitly executing a self provided method called "commit".

Every time a "commit" action is performed, the store will notify this update one and only to the "notifier" function.

Within the "notifier" function, you can customize how your application "reacts" to this event.

The Store

scribaX manages only #2 kind of data: "state" data and "computed" data.

A sample store would be something like this:

const store = new Store({
        state: {
                cards: [],
                engine: false,
                name: null,
                helmet: 0,
                round: 0
        },
        schema: {
                helmet: 'number',
                name: 'string',
                engine: 'boolean',
                cards: 'object',
                round: 'number'
        },
        computed: {
                Comp1: {
                        code: function () {
                                return this.helmet + this.round ;
                        }
                }
        }
});

Plain and simple, "state" data is the one you update(mutate) by invoking the "commit" method:

store.commit('round',4);

And "computed" data is derived state based on store state, by defining "getters" in the store. In the above example:

function () {
  return this.helmet + this.round ;
}

You can replace the store's root state at any given time by invoking the "replaceState" method:

var data = JSON.parse(document.querySelector('initialState').getAttribute('__APP_INITIAL_STATE__'));
store.replaceState(data);

With "replaceState", it throws out the current state and replaces it with only what you provide.
Use this only for "state hydration" purposes.

Validation Rules

In order to achieve predictability scribaX performs schema validation during updates.

To specify validation rules when creating a new store use the "schema" property:

        schema: {
                helmet: 'number',
                name: 'string',
                engine: 'boolean',
                cards: 'object',
                round: 'number'
        }

Reactions to updates

Simply connect a custom function to the self provided "notify" method, and that's it.

store.notify('notifier');

You can customize your "notifier" function as you wish:

function notifier(args) {
  const el = document.getElementById('commit');
  el.insertAdjacentHTML('beforeend',`<p>${args.state} now: ${args.value}</p>`);

  const elStore = document.getElementById('store');
  elStore.innerHTML = `round: ${store.round} win: ${store.win} helmet: ${store.helmet} myComp: ${store.Comp1}`;
}

What functionalites are not present here?

  • Reducers / Mutations: The goal of this project is to provide "only data" and not mixing "data" with "business logic".
  • Setters: A setter would be just another "business logic" snippet.
  • Actions: Again, more bussiness logic.

Installation via CDN

<script src="https://unpkg.com/scribax"></script>

Demos

Reach me out

Acknowledgements

Thanks to the incredible people who maintain projects such as Redux, Vuex and MobX et. al.

And thanks to all the people who share their knowledge and experiences freely on the Internet, you guys inspired this project.

License

MIT