@adrianhelvik/bind
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -12,2 +12,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "isObservable", { | ||
enumerable: true, | ||
get: function get() { | ||
return _isObservable["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "transaction", { | ||
@@ -43,2 +49,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "unwrap", { | ||
enumerable: true, | ||
get: function get() { | ||
return _unwrap["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "debug", { | ||
@@ -65,2 +77,4 @@ enumerable: true, | ||
var _isObservable = _interopRequireDefault(require("./isObservable.js")); | ||
var _transaction = _interopRequireDefault(require("./transaction.js")); | ||
@@ -76,2 +90,4 @@ | ||
var _unwrap = _interopRequireDefault(require("./unwrap.js")); | ||
var _debug = _interopRequireDefault(require("./debug.js")); | ||
@@ -78,0 +94,0 @@ |
@@ -6,2 +6,4 @@ "use strict"; | ||
}); | ||
exports.isObservable = isObservable; | ||
exports.unwrap = unwrap; | ||
exports["default"] = exports.GET_BINDING = void 0; | ||
@@ -19,4 +21,6 @@ | ||
var IS_OBSERVABLE = Symbol('IS_OBSERVABLE'); | ||
var GET_BINDING = Symbol('GET_BINDING'); | ||
exports.GET_BINDING = GET_BINDING; | ||
var UNWRAP = Symbol('UNWRAP'); | ||
var observables = new WeakMap(); | ||
@@ -27,2 +31,6 @@ | ||
if (isObservable(source)) { | ||
return source; | ||
} | ||
if (observables.has(source)) { | ||
@@ -40,2 +48,10 @@ return observables.get(source); | ||
get: function get(target, property, receiver) { | ||
if (property === UNWRAP) { | ||
return source; | ||
} | ||
if (property === IS_OBSERVABLE) { | ||
return true; | ||
} | ||
if (property === GET_BINDING) { | ||
@@ -123,2 +139,14 @@ return getBinding; | ||
var _default = observable; | ||
exports["default"] = _default; | ||
exports["default"] = _default; | ||
function isObservable(object) { | ||
return object && object[IS_OBSERVABLE]; | ||
} | ||
function unwrap(object) { | ||
if (!isObservable(object)) { | ||
return object; | ||
} | ||
return object[UNWRAP]; | ||
} |
@@ -37,2 +37,14 @@ "use strict"; | ||
expect(updated.size).toBe(1); | ||
}); | ||
it('does not make multiple observables for one object', function () { | ||
var real = {}; | ||
var obs1 = (0, _observable["default"])(real); | ||
var obs2 = (0, _observable["default"])(real); | ||
expect(obs1).toBe(obs2); | ||
}); | ||
it('does not wrap observables in observables', function () { | ||
var real = {}; | ||
var obs1 = (0, _observable["default"])(real); | ||
var obs2 = (0, _observable["default"])(obs1); | ||
expect(obs1).toBe(obs2); | ||
}); |
{ | ||
"name": "@adrianhelvik/bind", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "module": "src/index.js", |
import revertTransaction from './revertTransaction.js' | ||
import isObservable from './isObservable.js' | ||
import transaction from './transaction.js' | ||
@@ -7,2 +8,3 @@ import observable from './observable.js' | ||
import memoize from './memoize.js' | ||
import unwrap from './unwrap.js' | ||
import debug from './debug.js' | ||
@@ -14,2 +16,3 @@ import batch from './batch.js' | ||
revertTransaction, | ||
isObservable, | ||
transaction, | ||
@@ -20,2 +23,3 @@ observable, | ||
memoize, | ||
unwrap, | ||
debug, | ||
@@ -22,0 +26,0 @@ batch, |
@@ -5,6 +5,11 @@ import { manager } from './state.js' | ||
const IS_OBSERVABLE = Symbol('IS_OBSERVABLE') | ||
export const GET_BINDING = Symbol('GET_BINDING') | ||
const UNWRAP = Symbol('UNWRAP') | ||
const observables = new WeakMap() | ||
function observable(source = {}) { | ||
if (isObservable(source)) { | ||
return source | ||
} | ||
if (observables.has(source)) { | ||
@@ -19,2 +24,10 @@ return observables.get(source) | ||
get(target, property, receiver) { | ||
if (property === UNWRAP) { | ||
return source | ||
} | ||
if (property === IS_OBSERVABLE) { | ||
return true | ||
} | ||
if (property === GET_BINDING) { | ||
@@ -81,1 +94,12 @@ return getBinding | ||
export default observable | ||
export function isObservable(object) { | ||
return object && object[IS_OBSERVABLE] | ||
} | ||
export function unwrap(object) { | ||
if (!isObservable(object)) { | ||
return object | ||
} | ||
return object[UNWRAP] | ||
} |
@@ -33,1 +33,17 @@ import observable from './observable.js' | ||
}) | ||
it('does not make multiple observables for one object', () => { | ||
const real = {} | ||
const obs1 = observable(real) | ||
const obs2 = observable(real) | ||
expect(obs1).toBe(obs2) | ||
}) | ||
it('does not wrap observables in observables', () => { | ||
const real = {} | ||
const obs1 = observable(real) | ||
const obs2 = observable(obs1) | ||
expect(obs1).toBe(obs2) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84820
49
2511