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

bem-promised-models

Package Overview
Dependencies
Maintainers
4
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bem-promised-models

BEM wrapper for promised-models

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
4
Weekly downloads
 
Created
Source

bem-promised-models Build Status

BEM wrapper for promised-models2

Key features

  • support for BEM and bem-node
  • promise based (Vow Promises)
  • typed attributes
  • nested models and collections
  • async calculations and validation
  • can be used in priv.js with bem-node's i-state

Install

$ npm install --save bem-promised-models

Add node_modules/bem-promised-models/blocks to your levels lists

Add deps for promised-models

({
    mustDeps: [
        {block: 'promised-models', elems: ['model', 'registry', 'registry-storage']}
    ]
})

For noBEM setups use promised-models2

Usage

BEM.Model.decl('fashion-model', {
    attributes: {
        name: {
            type: 'String'
        }
    }
});

var model = BEM.blocks['fashion-model'].create({
    name: 'Kate'
});

model.get('name'); //Kate

Extend

Add declaration for existent one:

BEM.Model.decl('fashion-model', {
    attributes: {
        sename: {
            type: 'String'
        }
    },

    getFullName: function () {
        return [this.get('name') + this.get('sename')].join(' ');
    }
});

var model = BEM.blocks['fashion-model'].create({
    name: 'Kate',
    sename: 'Moss'
});

model.getFullName(); //Kate Moss

Inherit:

BEM.Model.decl('uppercased-model', 'fashion-model', {
    getFullName: function () {
        return this.__base().toUpperCase();
    }
});

Nested models and collections

BEM.Model.decl('podium', {
    attributes: {

        //nested
        currentModel: {
            type: 'Model',
            modelType: 'fashion-model'
        },

        //collections
        avaibleModels: {
            type: 'ModelsList',
            modelType: 'fashion-model'
        }
    }
});

Pass models by client id (for browser render only)

//bh template
var model = BEM.blocks['fashion-model'].create();
ctx.content({
    block: 'view',
    js: {
        modelId: model.cid
    }
});

//BEM.DOM declaration
var model = BEM.blocks['fashion-model'].getOne(this.params.modelId);

Find models by storage id

var model = BEM.blocks['fashion-model'].getAny(this.params.mongoId);

//load data from storage
model.fetch().done();

Define storage

BEM.Model.decl('fashion-model', {
   storage: {
        insert: function (model) {
            //...
        },

        update: function (model) {
            //...
        },

        find: function (model) {
            //...
        },

        remove: function (model) {
            //...
        }
   }
});

API

BEM.Model

.decl(modelName, [baseModel], [properties], [staticProperties])

Add model declaration

.getOne([cid])

Get model instance by client id model.cid

BEM.blocks['some-model']

.create([id], [data])

Create model instance with storage id and data

.getOne([cid])

Get model instance of current class by client id model.cid

.getAny([id])

Get model instance by storage id model.id. If no instance with id was found, create new one.

model instance

See promised-models2

Keywords

FAQs

Package last updated on 08 Apr 2016

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