New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

blueprint-js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blueprint-js

Full-featured JavaScript class creator. Simple, convenient API.

latest
Source
npmnpm
Version
1.3.2
Version published
Maintainers
1
Created
Source

Blueprint.js

API

// Import blueprint
import Blueprint from 'blueprint';
const type = Blueprint.type;

// Create a new class that extends a Blueprint class
// instead of type(t), you can pass in your own function that typecasts a value
const personAttrs = {
  id: type('number'),
  name: type('string'),
  color: type('string')
};
class Person extends Blueprint.build(personAttrs) {}

// Instantiate a new model
let kash = new Person({ id: 1, name: "Kash", color: "red" });
let sanjna = new Person({ id: 2, name: "Sanjna", color: "red" });

function logger() {
  console.log(...arguments);
}

// Models inherit from EventEmitter, so you can listen to events.
// By default, there are 2 events: `changed` and `changed:{attr}`,
// where {attr} is the attribute that is updated.
kash.on('changed', logger);
sanjna.on('changed:name', logger);

// Setting values in any way will automatically typecast them
// according to the types provided when you built the blueprint

// You can batch-update attributes with an object passed to `instance.update`
// This will notify 'changed:{attr}' listeners,
// and 'changed' listeners _once_ after all properties have been updated.
kash.update({ color: "navy" });
// the above will notify logger

// Or you can use regular JavaScript getters and setters
// (or the `instance.get` and `instance.set` methods).
// These will notify the 'changed:{attr}' and the 'changed' listeners.
sanjna.color = "yellow"; // or sanjna.set("color", "yellow");
// the above will not notify logger because logger is
// only listening to 'changed:name' events

// The `instance.toObject()` method will return the instance's attributes object
sanjna.toObject(); // returns { id: 2, name: "Sanjna", color: "yellow" }

// The `instance.toString()` is an alias for `instance.toObject().toJSON()`
kash.toString();

Keywords

Blueprint

FAQs

Package last updated on 12 Apr 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