GithubHelp home page GithubHelp logo

global_store's Introduction

🌎global_store

Quickstart

Import

<script src="dist/global_store.js"></script>

usage

const gs = new global_store();
// setting store
gs.setStore('test0', { a: 'b' });
// fetch from store
console.log(gs.fetchStore('test0 > a'));


// setting state
gs.setState('test1', 'hello');
// fetch from state
console.log(gs.fetchState('test1'));

gs.onStateUpdate = function (target, key, value) {
    console.log("===== upon state change =====");
    console.log(value);
};
gs.setState('test1', 'changed');

onStateUpdate is called whenever the state is changed

persist storage

// store item in session storage
gs.onStateUpdate = target => sessionStorage.setItem('gs',JSON.stringify(target))


// retrieve it when page loads
const gs = new global_store(JSON.parse(sessionStorage.getItem('gs')))

Build

Main File

tsc --outDir dist --target es5 --module ES6 --lib esnext global_store.ts

output es6

tsc --outDir dist --target es6 --module ESNext --lib esnext global_store.ts

  • The output file is a module than can be imported
  • HTML script embed version : Remove the bottom line export default global_store;

Testing file (not required)

tsc --outDir dist --target es5 --module ES6 --lib esnext,dom test.ts

global_store's People

Contributors

ac5tin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.