Giter Site home page Giter Site logo

hanetooth / cybobj Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 187 KB

Observable/Watchable JavaScript Objects

Home Page: https://github.com/hein-htut-aung/cybobj/blob/main/README.md

License: MIT License

JavaScript 37.59% TypeScript 62.41%
javascript-object observableobject watchable

cybobj's Introduction

CybObj

Observable/Watchable javaScript objects.

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install cybobj --save

# For Yarn, use the command below.
yarn add cybobj

Installation from CDN

This module has an UMD bundle available through JSDelivr and Unpkg CDNs.

<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/cybobj"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/cybobj"></script>

<script>
  // UMD module is exposed through the "CybObj" global variable.
  console.log(CybObj);
</script>

Usage

Unexpendable (default)

const assimilatedObj = new CybObj({
  name: { // name of the property
    value: 'John Doe', // value of the property
    onChange: (key, oldaVal, newVal) => {
      // on change listener
      // will emit on: assimilatedObj['name'] = 'Dohn Joe'
      console.log('Changed!', key, oldVal, newVal);
    },
    onAccess: (key, val) => {
      // "Optional" on access listener
      // will emit on: const someVar = assimilatedObj['name']
      console.log('Accessed!', key, val);
    },
  },
});

assimilatedObj['name'] = "Tony Stark";
// log: 'Changed!', 'name', 'John Doe', 'Tony Stark'

const name = assimilatedObj['name'];
// log: 'Accessed!', 'name', 'Tony Stark'

Expendable

Pass true as sencond parameter while instantiation object to be able to add new property with add .

Adding new property example.

assimilatedObj.add(key, {
  value: value,
  onChange: (key, oldVal, newVal) => {},
  onAccess: (key, val) => {},
});

API Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.

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.