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

binding-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binding-js - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

src/binding.js

13

package.json
{
"name": "binding-js",
"version": "0.2.0",
"version": "0.2.1",
"description": "Data binding modules.",
"main": "index.js",
"main": "src/binding.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "webpack ./test/test2.js test/bundle.js --watch"
},

@@ -20,4 +20,9 @@ "repository": {

"devDependencies": {
"observable-js": "^0.3.0"
"webpack": "^1.13.1"
},
"dependencies": {
"fastdom-js": "^0.1.0",
"observable-js": "^0.3.0",
"utility-js": "^0.1.0"
}
}
var PathObserver = require('./path-observer')
function Scope (object, parent) {
this.object = object
this.parent = parent
}
Scope.prototype = {
root: function () {
var root = this
while (root.parent && (root = root.parent)) {}
return root
},
val: function (path, value) {
var parts, object, part, root, key
if (value === undefined) {
if (path instanceof Object) {
for (var i in path) {
this.val(i, path[i])
}
return this
}
parts = path.split('.')
object = this.object
while (parts.length) {
part = parts.shift()
if (part === '$parent') {
if (!this.parent) {
return
}
object = this.parent.object
continue
} else if (part === '$root') {
root = this.root()
if (!root) {
return
}
object = root.object
continue
}
if (!(object instanceof Object)) {
return
}
if (!(part in object)) {
return
}
object = object[part]
}
return object
}
parts = path.split('.')
object = this.object
key = parts.pop()
if (parts.length) {
object = this.val(parts.join('.'))
}
if (!(object instanceof Object)) {
return this
}
if (object.isObservableObject) {
object.prop(key, value)
} else {
object[key] = value
}
return this
},
apply: function (path, args) {
var parts = path.split('.')
var object = this.object
var key = parts.pop()
if (parts.length) {
object = this.val(parts.join('.'))
}
if (!(object instanceof Object)) {
return
}
if (!(object[key] instanceof Function)) {
return
}
return object[key].apply(object, args)
},
call: function (path) {
return this.apply(path, Array.prototype.slice.call(arguments, 1))
},
observe: function (path, callback) {
new PathObserver(path, callback).observe(this.object)
return this
},
unobserve: function (path, callback) {
throw new Error('Not implemented yet')
}
}
module.exports = require('./scope')

@@ -13,5 +13,10 @@

var parts = this.path.split('.')
var initialize = true
var keyObserver = new KeyObserver(parts.pop(), {
observe: function () {
callback()
observe: function (object) {
if (initialize) {
initialize = false
return
}
callback(object)
}

@@ -18,0 +23,0 @@ })

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