@live-change/dao 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ const ObservableList = require("./ObservableList.js")
3
3
  const utils = require('./utils.js')
4
4
  const collectPointers = require('./collectPointers.js')
5
5
  const debug = require("debug")("reactive-dao")
6
+ const debugPot = require("debug")("reactive-dao:pot")
6
7
 
7
8
  class PushObservableTrigger {
8
9
  constructor(po, what, more) {
@@ -28,44 +29,43 @@ class PushObservableTrigger {
28
29
  ),
29
30
  remove: (value) => {
30
31
  const valueJson = JSON.stringify(value)
31
- this.removePointers(
32
- this.findPointers(
33
- localList.list.filter(v => JSON.stringify(v) == valueJson)
34
- )
35
- )
32
+ const existingElements = localList.list.filter(v => JSON.stringify(v) == valueJson)
33
+ const oldPointers = this.findPointers(existingElements)
34
+ this.removePointers(oldPointers, [])
36
35
  },
37
36
  removeByField: (fieldName, value) => {
38
37
  const valueJson = JSON.stringify(value)
39
- this.removePointers(
40
- this.findPointers(
41
- localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
42
- )
43
- )
38
+ const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
39
+ const oldPointers = this.findPointers(existingElements)
40
+ this.removePointers(oldPointers, [])
44
41
  },
45
42
  update: (value, update) => {
46
43
  const valueJson = JSON.stringify(value)
47
- this.replacePointers(
48
- this.findPointers(
49
- localList.list.filter(v => JSON.stringify(v) == valueJson)
50
- ),
51
- this.findPointers(
52
- localList.list.filter(v => JSON.stringify(v) == valueJson).map(u => update)
53
- )
54
- )
44
+ const existingElements = localList.list.filter(v => JSON.stringify(v) == valueJson)
45
+ const oldPointers = this.findPointers(existingElements)
46
+ const newPointers = this.findPointers(existingElements.map(u => update))
47
+ this.replacePointers(oldPointers, newPointers)
55
48
  },
56
49
  updateByField: (fieldName, value, update) => {
57
50
  const valueJson = JSON.stringify(value)
58
- this.replacePointers(
59
- this.findPointers(
60
- localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
61
- ),
62
- this.findPointers(
63
- localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson).map(u => update)
64
- )
51
+ const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
52
+ const oldPointers = this.findPointers(existingElements)
53
+ const newPointers = this.findPointers(existingElements.map(u => update))
54
+ this.replacePointers(oldPointers, newPointers)
55
+ },
56
+ putByField: (fieldName, value, update) => {
57
+ const valueJson = JSON.stringify(value)
58
+ const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
59
+ const oldPointers = this.findPointers(existingElements)
60
+ const newPointers = this.findPointers(
61
+ existingElements.length > 0 ? existingElements.map(u => update) : [ update ]
65
62
  )
63
+ console.log()
64
+ this.replacePointers(oldPointers, newPointers)
66
65
  }
67
66
  }
68
67
  this.observer = (signal, ...args) => {
68
+ debugPot("POT", this.what, "UPDATE SIGNAL", signal, args)
69
69
  if(this.pointerMethods[signal]) this.pointerMethods[signal](...args)
70
70
  if(localList[signal]) localList[signal](...JSON.parse(JSON.stringify(args)))
71
71
  }
@@ -74,6 +74,7 @@ class PushObservableTrigger {
74
74
  }
75
75
  }
76
76
  findPointers(value) {
77
+ debugPot("FIND POINTERS IN", value)
77
78
  let depsPointers = []
78
79
  let count = 0
79
80
  for(let dep of this.more) {
@@ -87,6 +88,7 @@ class PushObservableTrigger {
87
88
  what: pt,
88
89
  more: dep.more
89
90
  })
91
+ debugPot("FOUND POINTERS", allPointers)
90
92
  return allPointers
91
93
  }
92
94
  setPointers(allPointers) {
@@ -100,6 +102,7 @@ class PushObservableTrigger {
100
102
  this.commitPointersUpdate(added, removed)
101
103
  }
102
104
  replacePointers(oldPointers, newPointers) {
105
+ debugPot("REPLACE POINTERS", oldPointers, newPointers)
103
106
  let added = []
104
107
  let removed = []
105
108
  for(let pointer of newPointers) {
package/package.json CHANGED
@@ -35,6 +35,6 @@
35
35
  "scripts": {
36
36
  "test": "NODE_ENV=test blue-tape tests/*"
37
37
  },
38
- "version": "0.4.4",
39
- "gitHead": "9ddc0d69695d818a2b3a57bf0ff36a2b36133ea4"
38
+ "version": "0.4.5",
39
+ "gitHead": "1473e5de44d17cb2fb9b048d44adf6a75df10ce8"
40
40
  }