Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cjs-model

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cjs-model

Basic model implementation.

  • 1.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

STB SDK base model implementation

NPM version Dependencies Status Gitter

Represents domain-specific data or information that an application will be working with. A typical example is a user account (e.g name, avatar, e-mail) or a music track (e.g title, year, album). Holds information, but don’t handle behaviour and don’t format information or influence how data appears.

Installation

npm install stb-model

Usage

Add the constructor to the scope:

var Model = require('stb-model');

Create an empty instance:

var model = new Model();

Create an instance with some data:

var model = new Model({
	attr1: value1,
	attr2: value2,
});

Clear all data:

model.clear();

emits clear event in case some data is present

Clear and set new model data:

model.init({
	attr3: value3,
	attr4: value4,
});

can emit clear and init events

Check an attribute existence:

if ( model.has('attr3') ) {
    ...
}

Get a model attribute value by name:

var value = model.get('attr1');

Update or create a model attribute:

var operationStatus = model.set('attr5', 'value5');

emits change event with prev field in data in case of update operation

Delete the given attribute by name:

var operationStatus = model.unset('attr5');

emits change event

Performance notes

It is highly advisable to access a model data directly in case no events are required.

So instead of

var value = model.get('attr1');
model.set('attr5', 'value5');

to avoid performance penalty it's better to use

var value = model.data.attr1;
model.data.attr5 = 'value5';

Debug mode

There is a global var DEBUG which activates additional consistency checks and protection logic not available in release mode.

In debug mode the constructor is exposed to the global namespace as window.Model.

Contribution

If you have any problem or suggestion please open an issue here. Pull requests are welcomed with respect to the JavaScript Code Style.

License

stb-model is released under the GPL-3.0 License.

Keywords

FAQs

Package last updated on 16 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc