Skip to content

Commit af08765

Browse files
committed
Added filterMutationsToNode
1 parent 9fd7fc1 commit af08765

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

src/api/action.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
dop.action = function(f) {
1+
dop.action = function(f, filterMutationsToNode) {
22
dop.util.invariant(
33
isFunction(f),
4-
'dop.action only accept one argument as function'
4+
'dop.action needs one argument as function'
55
)
66
return function() {
77
var collectors = dop.data.collectors
88
var collector = dop.core.createCollector(collectors, collectors.length)
99
var output = f.apply(this, arguments)
10-
collector.emit()
10+
collector.emit(filterMutationsToNode)
1111
return output
1212
}
1313
}

src/core/constructors/collector.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ dop.core.collector.prototype.add = function(mutation) {
1616
return false
1717
}
1818

19-
dop.core.collector.prototype.emit = function(shallWeEmitToNode) {
19+
dop.core.collector.prototype.emit = function(filterMutationsToNode) {
2020
this.destroy()
21-
return this.emitWithoutDestroy(shallWeEmitToNode)
21+
return this.emitWithoutDestroy(filterMutationsToNode)
2222
}
2323

24-
dop.core.collector.prototype.emitWithoutDestroy = function(shallWeEmitToNode) {
24+
dop.core.collector.prototype.emitWithoutDestroy = function(
25+
filterMutationsToNode
26+
) {
2527
var snapshot = new dop.core.snapshot(this.mutations)
26-
snapshot.emit(shallWeEmitToNode)
28+
snapshot.emit(filterMutationsToNode)
2729
this.mutations = []
2830
return snapshot
2931
}

src/core/constructors/snapshot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ dop.core.snapshot.prototype.redo = function() {
1717
}
1818
}
1919

20-
dop.core.snapshot.prototype.emit = function(shallWeEmitToNode) {
20+
dop.core.snapshot.prototype.emit = function(filterMutationsToNode) {
2121
if (this.mutations.length > 0) {
22-
dop.core.emitToObservers(this, shallWeEmitToNode)
22+
dop.core.emitToObservers(this, filterMutationsToNode)
2323
}
2424
}
2525

src/core/objects/emitToObservers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dop.core.emitToObservers = function(snapshot, shallWeEmitToNode) {
1+
dop.core.emitToObservers = function(snapshot, filterMutationsToNode) {
22
var mutations = snapshot.mutations,
33
mutation,
44
path_id,
@@ -75,7 +75,7 @@ dop.core.emitToObservers = function(snapshot, shallWeEmitToNode) {
7575
// We need to make sure that the observer still exists, because maybe has been removed after calling previous observers
7676
observer.callback(
7777
mutations_by_observers[observer_id],
78-
shallWeEmitToNode
78+
filterMutationsToNode
7979
)
8080
}
8181

src/core/protocol/registerSubscriber.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
dop.core.registerSubscriber = function(node, object, object_path_id) {
2-
var observer = dop.createObserver(function(mutations, shallWeEmitToNode) {
2+
var observer = dop.createObserver(function(
3+
mutations,
4+
filterMutationsToNode
5+
) {
6+
if (typeof filterMutationsToNode == 'function')
7+
mutations = filterMutationsToNode(mutations, node)
8+
39
var object_id,
410
chunks,
511
patch = dop.core.getPatch(mutations)
612
for (object_id in patch) {
713
chunks = patch[object_id].chunks
814
dop.protocol.patch(node, object_path_id, chunks, subscriber)
15+
return
916
}
1017
})
1118
var subscriber = {

0 commit comments

Comments
 (0)