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

felisjs

v1.0.2

Published

Simple statement container with timetraveling

Downloads

6

Readme

Felis.js

Simple statement container with time traveling

Installing

npm install felisjs --save

or

yarn add felisjs

Using

Initialization

You can either use require() or just add script by using

<script src="<address to felisjs>"></sciprt>
const Storage = require('felisjs');

// init empty storage and then add some containers 

const storage = new Storage();
storage.add('stringContainer', 'string data');
storage.add('data');
storage.data.add('someNumber', 5);
storage.data.add('someArray', []);

// or init with special object

const storage = new Storage({
    stringContainer: 'string data',
    data: {
        someNumber: 5,
        someArray: []
    }
});

// these examples are equal

Getting and setting data


storage.stringData.get() // 'string data';
storage.stringData.set('Hello world!') // 'Hello world!'
storage.stringData.get() // 'Hello world!';

Subscribing to data changing

You can subscribe any functions to some container and any time value of that container changes functions are called


const foo = (x) => {
    console.log(`foo was called with ${x}`);
}
const bar = (x) => {
    console.log(`bar was called with ${x}`);
}

// Methods .subscribe and .sub are equal
storage.data.someNumber.subscribe(bar);
storage.data.someNumber.sub(foo);
storage.data.someNumber.sub(function(x) {
    console.log(`Common anonimous function was called with ${x}`);
});
storage.data.someNumber.sub((x) => {
    console.log(`Arrow anonimous function was called with ${x}`);
});

storage.data.someNumber.set(10);

/* it will log
foo was called with 10
bar was called with 10
Common anonymous function was called with 10
Arrow anonymous function was called with 10
*/

// You also can unsubscibe functions
storage.data.someNumber.unsubscribe(bar);
storage.data.someNumber.unsub(foo);

storage.data.someNumber.set(20);
/* it will log
Common anonimous function was called with 20
Arrow anonimous function was called with 20
*/

Time traveling

To handle time traveling (ctrl-z, ctrl-shift-z) you need to save copies of storage somewhere and then update current storage with previously saved


const Storage = require('felisjs');
const storage = new Storage();

const storage.add('editableText', 'Write something...');

storage.editableText.sub((newText) => {
    console.info(`Text has been changed to ${newText}`);
    // do something
});


const storages = [storage];
let currentStoragePosition = 0;

let lastHandledStorage = storage.clone();
storage.editableText.sub((newText) => {
    if (lastHandledStorage.editableText.get() !== newText) {
        while (currentStoragePosition > 0) {
            currentStoragePosition--;
            storages.shift();
        }
        storages.push(lastHandledStorage);
        lastHandledStorage = storage.clone();
    }
});

// ctrl-z
const goBack = () => {
    if (currentStoragePosition < storages.length - 1) {
        currentStoragePosition++;
        storage.update(storages[currentStoragePosition]);
    }
}
// ctrl-shift-z
const goForward = () => {
    if (currentStoragePosition > 1) {
        currentStoragePosition--;
        storage.update(storages[currentStoragePosition]);
    }
}

Run test

npm test

Install dev dependencies

npm install --only=dev

Build debug and dist

npm build

watcher

npm watch

Author

You can contact me via Telegram @phytonmk