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

mvcobject

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mvcobject - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

5

MVCObject.d.ts
export declare class Accessor {
target: MVCObject;
targetKey: string;
from: Function;
to: Function;
constructor(target: MVCObject, targetKey: string);
transform(from: Function, to: Function): void;
}

@@ -43,3 +40,3 @@ export declare class MVCObject {

*/
bindTo(key: string, target: MVCObject, targetKey?: string, noNotify?: boolean): Accessor;
bindTo(key: string, target: MVCObject, targetKey?: string, noNotify?: boolean): MVCObject;
/**

@@ -46,0 +43,0 @@ * @description 解除当前对象上key与目标对象的监听

29

MVCObject.js

@@ -18,7 +18,2 @@ (function (factory) {

;
Accessor.prototype.transform = function (from, to) {
this.from = from;
this.to = to;
this.target.notify(this.targetKey);
};
return Accessor;

@@ -29,11 +24,11 @@ }());

var setterNameCache = {};
var uuid = 0;
var bindings = '__bindings__';
var accessors = '__accessors__';
var uid = '__uid__';
var ooid = 0;
var bindings = '__o_bindings';
var accessors = '__o_accessors';
var oid = '__o_oid';
function capitalize(str) {
return str.substr(0, 1).toUpperCase() + str.substr(1);
}
function getUid(obj) {
return obj[uid] || (obj[uid] = ++uuid);
function getOid(obj) {
return obj[oid] || (obj[oid] = ++ooid);
}

@@ -114,5 +109,2 @@ function toKey(key) {

}
if (accessor.to) {
value = accessor.to(value);
}
}

@@ -138,5 +130,2 @@ else if (self.hasOwnProperty(toKey(key))) {

var setterName = getSetterName(targetKey);
if (accessor.from) {
value = accessor.from(value);
}
if (target[setterName]) {

@@ -217,7 +206,7 @@ target[setterName](value);

self[accessors][key] = accessor;
target[bindings][targetKey][getUid(self)] = binding;
target[bindings][targetKey][getOid(self)] = binding;
if (!noNotify) {
triggerChange(self, key);
}
return accessor;
return self;
};

@@ -237,3 +226,3 @@ /**

self[toKey(key)] = self.get(key);
delete target[bindings][targetKey][getUid(self)];
delete target[bindings][targetKey][getOid(self)];
delete self[accessors][key];

@@ -240,0 +229,0 @@ }

@@ -1,1 +0,1 @@

!function(t){if("object"==typeof module&&"object"==typeof module.exports){var e=t(require,exports);void 0!==e&&(module.exports=e)}else"function"==typeof define&&define.amd&&define(["require","exports"],t)}(function(t,e){"use strict";function r(t){return t.substr(0,1).toUpperCase()+t.substr(1)}function n(t){return t[d]||(t[d]=++c)}function o(t){return"_"+t}function i(t){return f.hasOwnProperty(t)?f[t]:f[t]="get"+r(t)}function a(t){return p.hasOwnProperty(t)?p[t]:p[t]="set"+r(t)}function u(t,e){var r=e+"_changed";if(t[r]?t[r]():"function"==typeof t.changed&&t.changed(e),t[y]&&t[y][e]){var n,o,i=t[y][e];for(o in i)i.hasOwnProperty(o)&&(n=i[o],u(n.target,n.targetKey))}}e.__esModule=!0;var s=function(){function t(t,e){this.target=t,this.targetKey=e}return t.prototype.transform=function(t,e){this.from=t,this.to=e,this.target.notify(this.targetKey)},t}();e.Accessor=s;var f={},p={},c=0,y="__bindings__",h="__accessors__",d="__uid__",g=function(){function t(){}return t.prototype.get=function(t){var e=this;if(e[h]&&e[h].hasOwnProperty(t)){var r,n=e[h][t],a=n.targetKey,u=n.target,s=i(a);r=u[s]?u[s]():u.get(a),n.to&&(r=n.to(r))}else e.hasOwnProperty(o(t))&&(r=e[o(t)]);return r},t.prototype.set=function(t,e){var r=this;if(r[h]&&r[h].hasOwnProperty(t)){var n=r[h][t],i=n.targetKey,s=n.target,f=a(i);n.from&&(e=n.from(e)),s[f]?s[f](e):s.set(i,e)}else this[o(t)]=e,u(r,t);return r},t.prototype.changed=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e]},t.prototype.notify=function(t){var e=this;if(e[h]&&e[h].hasOwnProperty(t)){var r=e[h][t],n=r.targetKey;r.target.notify(n)}else u(e,t);return e},t.prototype.setValues=function(t){var e,r,n,o=this;for(e in t)t.hasOwnProperty(e)&&(n=t[e],r=a(e),o[r]?o[r](n):o.set(e,n));return o},t.prototype.bindTo=function(t,e,r,o){void 0===r&&(r=t);var i=this;i.unbind(t),i[h]||(i[h]={}),e[y]||(e[y]={}),e[y][r]||(e[y][r]={});var a=new s(i,t),f=new s(e,r);return i[h][t]=f,e[y][r][n(i)]=a,o||u(i,t),f},t.prototype.unbind=function(t){var e=this;if(e[h]){var r=e[h][t];if(r){var i=r.target,a=r.targetKey;e[o(t)]=e.get(t),delete i[y][a][n(e)],delete e[h][t]}}return e},t.prototype.unbindAll=function(){var t=this;if(t[h]){var e=t[h];for(var r in e)e.hasOwnProperty(r)&&t.unbind(r)}return t},t}();e.MVCObject=g,e.default=g});
!function(t){if("object"==typeof module&&"object"==typeof module.exports){var e=t(require,exports);void 0!==e&&(module.exports=e)}else"function"==typeof define&&define.amd&&define(["require","exports"],t)}(function(t,e){"use strict";function r(t){return t.substr(0,1).toUpperCase()+t.substr(1)}function n(t){return t[h]||(t[h]=++c)}function o(t){return"_"+t}function i(t){return f.hasOwnProperty(t)?f[t]:f[t]="get"+r(t)}function a(t){return p.hasOwnProperty(t)?p[t]:p[t]="set"+r(t)}function u(t,e){var r=e+"_changed";if(t[r]?t[r]():"function"==typeof t.changed&&t.changed(e),t[y]&&t[y][e]){var n,o,i=t[y][e];for(o in i)i.hasOwnProperty(o)&&(n=i[o],u(n.target,n.targetKey))}}e.__esModule=!0;var s=function(){function t(t,e){this.target=t,this.targetKey=e}return t}();e.Accessor=s;var f={},p={},c=0,y="__o_bindings",d="__o_accessors",h="__o_oid",v=function(){function t(){}return t.prototype.get=function(t){var e=this;if(e[d]&&e[d].hasOwnProperty(t)){var r,n=e[d][t],a=n.targetKey,u=n.target,s=i(a);r=u[s]?u[s]():u.get(a)}else e.hasOwnProperty(o(t))&&(r=e[o(t)]);return r},t.prototype.set=function(t,e){var r=this;if(r[d]&&r[d].hasOwnProperty(t)){var n=r[d][t],i=n.targetKey,s=n.target,f=a(i);s[f]?s[f](e):s.set(i,e)}else this[o(t)]=e,u(r,t);return r},t.prototype.changed=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e]},t.prototype.notify=function(t){var e=this;if(e[d]&&e[d].hasOwnProperty(t)){var r=e[d][t],n=r.targetKey;r.target.notify(n)}else u(e,t);return e},t.prototype.setValues=function(t){var e,r,n,o=this;for(e in t)t.hasOwnProperty(e)&&(n=t[e],r=a(e),o[r]?o[r](n):o.set(e,n));return o},t.prototype.bindTo=function(t,e,r,o){void 0===r&&(r=t);var i=this;i.unbind(t),i[d]||(i[d]={}),e[y]||(e[y]={}),e[y][r]||(e[y][r]={});var a=new s(i,t),f=new s(e,r);return i[d][t]=f,e[y][r][n(i)]=a,o||u(i,t),i},t.prototype.unbind=function(t){var e=this;if(e[d]){var r=e[d][t];if(r){var i=r.target,a=r.targetKey;e[o(t)]=e.get(t),delete i[y][a][n(e)],delete e[d][t]}}return e},t.prototype.unbindAll=function(){var t=this;if(t[d]){var e=t[d];for(var r in e)e.hasOwnProperty(r)&&t.unbind(r)}return t},t}();e.MVCObject=v,e.default=v});
export class Accessor{
from: Function;
to: Function;
constructor(public target: MVCObject, public targetKey: string){};
transform(from: Function, to: Function){
this.from = from;
this.to = to;
this.target.notify(this.targetKey);
}
}

@@ -16,6 +7,6 @@

let setterNameCache = {};
let uuid = 0;
let bindings = '__bindings__';
let accessors = '__accessors__';
let uid = '__uid__';
let ooid = 0;
let bindings = '__o_bindings';
let accessors = '__o_accessors';
let oid = '__o_oid';

@@ -26,4 +17,4 @@ function capitalize(str: string) {

function getUid(obj: MVCObject) {
return obj[uid] || (obj[uid] = ++uuid);
function getOid(obj: MVCObject) {
return obj[oid] || (obj[oid] = ++ooid);
}

@@ -106,5 +97,2 @@

}
if (accessor.to) {
value = accessor.to(value);
}
} else if (self.hasOwnProperty(toKey(key))) {

@@ -130,5 +118,2 @@ value = self[toKey(key)];

var setterName = getSetterName(targetKey);
if (accessor.from) {
value = accessor.from(value);
}
if (target[setterName]) {

@@ -194,3 +179,3 @@ target[setterName](value);

*/
bindTo(key: string, target: MVCObject, targetKey: string = key, noNotify?: boolean): Accessor{
bindTo(key: string, target: MVCObject, targetKey: string = key, noNotify?: boolean): MVCObject{
var self = this;

@@ -207,3 +192,3 @@ self.unbind(key);

self[accessors][key] = accessor;
target[bindings][targetKey][getUid(self)] = binding;
target[bindings][targetKey][getOid(self)] = binding;

@@ -214,3 +199,3 @@ if (!noNotify) {

return accessor;
return self;
}

@@ -231,3 +216,3 @@

self[toKey(key)] = self.get(key);
delete target[bindings][targetKey][getUid(self)];
delete target[bindings][targetKey][getOid(self)];
delete self[accessors][key];

@@ -234,0 +219,0 @@ }

{
"name": "mvcobject",
"version": "1.2.0",
"version": "2.0.0",
"description": "An implementation of Google Maps' MVCObject for Node.js and browers",

@@ -5,0 +5,0 @@ "main": "MVCObject.js",

@@ -13,3 +13,3 @@ ## MVCObject [![NPM version](https://badge.fury.io/js/mvcobject.png)](http://badge.fury.io/js/mvcobject) [![Build Status](https://travis-ci.org/Treri/MVCObject.png)](https://travis-ci.org/Treri/MVCObject) [![Dependencies Status](https://david-dm.org/Treri/MVCObject.png)](https://david-dm.org/Treri/MVCObject)

----- | ----- | -----
bindTo(key:string, target:MVCObject, targetKey?:string, noNotify?:boolean) | accessor | Binds a View to a Model.
bindTo(key:string, target:MVCObject, targetKey?:string, noNotify?:boolean) | this | Binds a View to a Model.
changed(key:string) | ? | Generic handler for state changes. Override this in derived classes to handle arbitrary state changes.

@@ -24,12 +24,7 @@ get(key:string) | * | Gets a value.

### Usage
0. Install
```bash
npm install mvcobject
```
- ES6
1. ES6
```js
import {MVCObject} from 'MVCObject'
import MVCObject from 'mvcobject'

@@ -43,2 +38,10 @@ class Foo extends MVCObject{

- ES5
```js
var MVCObject = require('mvcobject').MVCObject;
function Foo(){}
Foo.prototype = new MVCObject();
```
### test

@@ -53,3 +56,3 @@ Thanks to @twpayne, the test suites are based on his [mvcobject_test.js](https://github.com/twpayne/mvcobject/blob/master/src/mvc/mvcobject_test.js).

Copyright (c) 2013-2016 Treri treri.liu@gmail.com
Copyright (c) 2013 - present Treri treri.liu@gmail.com

@@ -56,0 +59,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

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