Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
backbone.viewmodel
Advanced tools
Backbone.ViewModel implementation with attributes mapping and agile synchronization.
Yes, YA Backbone.ViewModel here! Because we are can! :)
Actually I need solutions to link two different Views on base of one Model and ViewModel is matter. See example project for more details.
Backbone.ViewModel may used between Model and View in Backbone or BB.Marionette or other BB-compatibility projects.
Its not drop-in replacement for Model, but it handle correctly some methods and properties form Model and should play well with others (you may write request with testcase if important Madel functionality looks omitted).
As ViewModel its support some additional features as computed values, controlled autosync with Model and defaults values.
npm install backbone.viewmodel
Get copy of /browser_lib/backbone.viewmodel.js
or use CommonJS-style with clinch.
All examples written with CoffeeScript, you may use plain JS instead (but why?).
How its works:
class RectangleViewModel extends Backbone.ViewModel
autoupdate : on
mapping :
color : 'color'
width : 'size'
height : 'getHeight'
getHeight : ->
@model.get('size') * ( 1 + Math.random() ) | 0
rectangle = new RectangleViewModel color : 'blue', size : 20
console.log rectangle.toJSON() # -> Object {color: "blue", width: 20, height: 22}
rectangle.model.set 'size', 50 # its bad example of `model` interaction, but ok here
console.log rectangle.toJSON() # -> Object {color: "blue", width: 50, height: 74}
Backbone.ViewModel have few methods and some numbers of class properties.
###
model prop may be used to create specific Model from raw data,
by default VM use Backbone.Model
###
model : BaseBB.Model
###
VM do not auto-update itself properties on model changes
use this knob to turn it on
###
autoupdate : on
###
all keys in mapping will be 'mapped' self VM functions OR
model attributes, with priority: function, than attributes
###
mapping :
color : 'color'
height : 'getHeight'
dataIn
- BB.Model or raw data objectconstructorAttrs
- default VM properties may be placed hereoptions
- some options, like autoupdate
Just proceed process to update VM from current model state. May be called if autoupdate
property not used for some reason.
Backbone.ViewModel as BB.Model will support much helpfully methods like toJSON()
or get()
, dozen unsuitably methods like set()
unset()
or clear()
and (at now) will available to call erroneously methods like fetch()
or sync()
- just do not use them.
If you need to have synced model - create it first and use thyself methods in ViewModel update
or autoupdate
combinations.
0.0.9 / 2013-05-25 02:00 AM
FAQs
Backbone.ViewModel implementation with attributes mapping and agile synchronization.
The npm package backbone.viewmodel receives a total of 2 weekly downloads. As such, backbone.viewmodel popularity was classified as not popular.
We found that backbone.viewmodel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.