Skip to content

Commit 5fc19ed

Browse files
committed
Allowing registrable Classes
1 parent 0375f72 commit 5fc19ed

File tree

10 files changed

+41
-39
lines changed

10 files changed

+41
-39
lines changed

src/api/isObjectRegistrable.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
21
dop.isObjectRegistrable = function(object) {
3-
if (object === null || typeof object !== "object") return false;
4-
var prototype = Object.getPrototypeOf(object);
5-
return prototype === Object.prototype || prototype === Array.prototype;
6-
};
7-
8-
//dop.isObjectRegistrable = function(object) {
9-
// var tof = dop.util.typeof(object);
10-
// return (tof === 'object' || tof == 'array');
11-
// };
12-
13-
// function Test(){}
14-
// console.log(isObjectRegistrable({}));
15-
// console.log(isObjectRegistrable([]));
16-
// console.log(isObjectRegistrable(new Test));
17-
// console.log(isObjectRegistrable(new Map));
18-
// console.log(isObjectRegistrable(new Date()));
19-
// console.log(isObjectRegistrable(null));
20-
// console.log(isObjectRegistrable(Symbol('')));
21-
// console.log(isObjectRegistrable(function(){}));
22-
// console.log(isObjectRegistrable(1));
23-
// console.log(isObjectRegistrable("s"));
24-
// console.log(isObjectRegistrable(true));
25-
// console.log(isObjectRegistrable(/a/));
2+
return isObject(object);
3+
};

src/api/isPojoObject.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
dop.isPojoObject = function(object) {
2+
if (object === null || typeof object !== "object") return false;
3+
var prototype = Object.getPrototypeOf(object);
4+
return prototype === Object.prototype || prototype === Array.prototype;
5+
};
6+
7+
8+
// dop.isPojoObject = function(object) {
9+
// var tof = dop.util.typeof(object);
10+
// return (tof === 'object' || tof == 'array');
11+
// };
12+
13+
// function Test(){}
14+
// console.log(dop.isPojoObject({}));
15+
// console.log(dop.isPojoObject([]));
16+
// console.log(dop.isPojoObject(new Error));
17+
// console.log(dop.isPojoObject(new Date()));
18+
// console.log(dop.isPojoObject(null));
19+
// console.log(dop.isPojoObject(Symbol('')));
20+
// console.log(dop.isPojoObject(function(){}));
21+
// console.log(dop.isPojoObject(1));
22+
// console.log(dop.isPojoObject("s"));
23+
// console.log(dop.isPojoObject(true));
24+
// console.log(dop.isPojoObject(/a/));

src/api/register.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
dop.register = function(object) {
3-
dop.util.invariant(dop.isObjectRegistrable(object) && !isArray(object), 'dop.register needs a regular plain object as first parameter');
3+
dop.util.invariant(dop.isObjectRegistrable(object) && !isArray(object), 'dop.register needs an object or an array as first parameter');
44
return (dop.isRegistered(object)) ?
55
dop.getObjectProxy(object)
66
:

src/core/mutators/set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dop.core.set = function(object, property, value, options) {
2525
// property = Number(property);
2626

2727
// object or array
28-
if (options.deep && dop.isObjectRegistrable(value) && !(dop.isRegistered(value) && dop.getObjectParent(value) === objectProxy))
28+
if (options.deep && dop.isPojoObject(value) && !(dop.isRegistered(value) && dop.getObjectParent(value) === objectProxy))
2929
objectTarget[property] = dop.core.configureObject(value, property, objectProxy);
3030
// computed value
3131
else if (isFunction(value) && value._name==dop.cons.COMPUTED_FUNCTION)

src/core/mutators/splice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dop.core.splice = function(array, args) {
4545
// We must register new objects
4646
for (;index<argslength; ++index, ++start) {
4747
item = args[index];
48-
if (dop.isObjectRegistrable(item))
48+
if (dop.isPojoObject(item))
4949
objectTarget[start] = dop.core.configureObject(
5050
item,
5151
start,

src/core/objects/configureObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ dop.core.configureObject = function(object, propertyParent, parent) {
7474
else if (is_function && value._name==dop.cons.COMPUTED_FUNCTION)
7575
object_target[property] = value(object_proxy, property, false, undefined);
7676
// object or array
77-
else if (dop.isObjectRegistrable(value))
77+
else if (dop.isPojoObject(value))
7878
object_target[property] = dop.core.configureObject(value, property, object_proxy);
7979
}
8080

src/protocol/onsubscribe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dop.protocol.onsubscribe = function(node, request_id, request) {
66
var params = Array.prototype.slice.call(request, 1);
77

88
dop.core.localProcedureCall(dop.data.onsubscribe, params, function resolve(value) {
9-
if (dop.isObjectRegistrable(value)) {
9+
if (dop.isPojoObject(value)) {
1010
var object = dop.register(value),
1111
object_root = dop.getObjectRoot(object),
1212
object_path = dop.getObjectPath(object),

src/protocol/subscribe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dop.protocol.subscribe = function(node, params) {
44
params.unshift(node, dop.protocol.instructions.subscribe);
55
var request = dop.core.createRequest.apply(node, params);
66
request.promise.into = function(object) {
7-
if (dop.isObjectRegistrable(object))
7+
if (dop.isPojoObject(object))
88
request.into = (dop.isRegistered(object)) ? dop.getObjectProxy(object) : object;
99
delete request.promise.into
1010
return request.promise;

src/util/clone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
dop.util.clone = function(value) {
3-
return (dop.isObjectRegistrable(value)) ?
3+
return (dop.isPojoObject(value)) ?
44
dop.util.merge(isArray(value) ? [] : {}, value)
55
:
66
value;

test/zarrays.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function gify(obj) {
1010
this.myClassProperty=123;
1111
return JSON.stringify(obj);
1212
}
13-
var isObjectRegistrable = dop.isObjectRegistrable;
13+
var isPojoObject = dop.isPojoObject;
1414

1515

1616

@@ -34,7 +34,7 @@ test('Splice', function(t) {
3434

3535
for (var index=0,total=register.length; index<total; ++index) {
3636
var item = register[index];
37-
if (isObjectRegistrable(item)) {
37+
if (isPojoObject(item)) {
3838

3939
if (dop.isRegistered(item)) {
4040
var property = dop.getObjectProperty(item);
@@ -61,7 +61,7 @@ test('Shift', function(t) {
6161
t.deepEqual(original,register, 'deepEqual case: '+description);
6262
for (var index=0,total=register.length; index<total; ++index) {
6363
var item = register[index];
64-
if (isObjectRegistrable(item)) {
64+
if (isPojoObject(item)) {
6565

6666
if (dop.isRegistered(item)) {
6767
var property = dop.getObjectProperty(item);
@@ -89,7 +89,7 @@ test('Pop', function(t) {
8989
t.deepEqual(original,register, 'deepEqual case: '+description);
9090
for (var index=0,total=register.length; index<total; ++index) {
9191
var item = register[index];
92-
if (isObjectRegistrable(item)) {
92+
if (isPojoObject(item)) {
9393

9494
if (dop.isRegistered(item)) {
9595
var property = dop.getObjectProperty(item);
@@ -115,7 +115,7 @@ test('Push', function(t) {
115115
t.equal(gify(register.push.apply(register, paramsCase)), gify(original.push.apply(original, paramsCase)), 'output case: '+description);
116116
for (var index=0,total=register.length; index<total; ++index) {
117117
var item = register[index];
118-
if (isObjectRegistrable(item)) {
118+
if (isPojoObject(item)) {
119119

120120
if (dop.isRegistered(item)) {
121121
var property = dop.getObjectProperty(item);
@@ -144,7 +144,7 @@ test('Unshift', function(t) {
144144

145145
for (var index=0,total=register.length; index<total; ++index) {
146146
var item = register[index];
147-
if (isObjectRegistrable(item)) {
147+
if (isPojoObject(item)) {
148148

149149
if (dop.isRegistered(item)) {
150150
var property = dop.getObjectProperty(item);
@@ -168,7 +168,7 @@ test('Reverse', function(t) {
168168
t.deepEqual(original,register, 'deepEqual case');
169169
for (var index=0,total=register.length; index<total; ++index) {
170170
var item = register[index];
171-
if (isObjectRegistrable(item)) {
171+
if (isPojoObject(item)) {
172172
dop.getObjectPath(item);
173173
if (dop.isRegistered(item)) {
174174
var property = dop.getObjectProperty(item);
@@ -232,7 +232,7 @@ test('Sort', function(t) {
232232
t.deepEqual(arrayOriginal, copy, 'deepEqual function:'+compareFunction);
233233
for (var index=0,total=arrayOriginal.length; index<total; ++index) {
234234
var item = arrayOriginal[index];
235-
if (isObjectRegistrable(item)) {
235+
if (isPojoObject(item)) {
236236

237237
if (dop.isRegistered(item)) {
238238
dop.getObjectPath(item);

0 commit comments

Comments
 (0)