@live-change/dao 0.4.13 → 0.5.2

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.
package/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2019-2022 Michał Łaszczewski
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,10 +1,11 @@
1
1
 
2
2
  class InboxReader {
3
- constructor(observableFunction, callback, start = '', bucketSize = 32) {
3
+ constructor(observableFunction, callback, start = '', bucketSize = 32, idField = 'id') {
4
4
  this.observableFunction = observableFunction
5
5
  this.position = start
6
6
  this.callback = callback
7
7
  this.bucketSize = bucketSize
8
+ this.idField = idField
8
9
 
9
10
  this.observable = null
10
11
  this.queue = []
@@ -28,8 +29,8 @@ class InboxReader {
28
29
  this.handleMessage(message)
29
30
  }
30
31
  } else if(signal == 'push') {
31
- const [message] = args
32
- this.handleMessage(message)
32
+ const [...messages] = args
33
+ for(const message of messages) this.handleMessage(message)
33
34
  } else {
34
35
  console.error("INBOX READER SIGNAL NOT HANDLED", signal)
35
36
  }
@@ -56,8 +57,8 @@ class InboxReader {
56
57
  }
57
58
 
58
59
  handleMessage(message) {
59
- if(message.id <= this.position) return // ignore
60
- this.position = message.id
60
+ if(message[this.idField] <= this.position) return // ignore
61
+ this.position = message[this.idField]
61
62
  this.queue.push(message)
62
63
  }
63
64
 
package/lib/Observable.js CHANGED
@@ -35,7 +35,8 @@ class Observable {
35
35
 
36
36
  handleError(error) {
37
37
  let handled = false
38
- for (var observer of this.errorObservers) {
38
+ if(!error) return true /// ignore null errors!
39
+ for (let observer of this.errorObservers) {
39
40
  handled = true
40
41
  observer(error)
41
42
  }
@@ -98,6 +99,8 @@ class Observable {
98
99
 
99
100
  const waitPromise = new Promise((resolve, reject) => {
100
101
  errorObserver = (error) => {
102
+ console.log("ERROR SIGNAL", error)
103
+ console.trace("WEER")
101
104
  if(resultObserver) this.unobserve(resultObserver)
102
105
  resultObserver = undefined
103
106
  if(errorObserver) this.uncatch(errorObserver)
@@ -18,6 +18,7 @@ class ObservableList extends Observable {
18
18
  }
19
19
 
20
20
  set(list) {
21
+ this.handleError(null)
21
22
  if(list === this.list) return
22
23
  try {
23
24
  if (JSON.stringify(list) == JSON.stringify(this.list)) return
@@ -30,26 +31,32 @@ class ObservableList extends Observable {
30
31
  }
31
32
 
32
33
  push(value) {
34
+ this.handleError(null)
33
35
  this.list.push(value)
34
36
  this.fireObservers('push', value)
35
37
  }
36
38
  unshift(value) {
39
+ this.handleError(null)
37
40
  this.list.unshift(value)
38
41
  this.fireObservers('unshift', value)
39
42
  }
40
43
  pop() {
44
+ this.handleError(null)
41
45
  this.list.pop()
42
46
  this.fireObservers('pop')
43
47
  }
44
48
  shift() {
49
+ this.handleError(null)
45
50
  this.list.shift()
46
51
  this.fireObservers('shift')
47
52
  }
48
53
  splice(at, del, ...values) {
54
+ this.handleError(null)
49
55
  this.list.splice(at, del, ...values)
50
56
  this.fireObservers('splice', at, del, ...values)
51
57
  }
52
58
  putByField(field, value, element, reverse = false, oldElement) {
59
+ this.handleError(null)
53
60
  if(!reverse) {
54
61
  let i, l
55
62
  for(i = 0, l = this.list.length; i < l; i++) {
@@ -80,6 +87,7 @@ class ObservableList extends Observable {
80
87
  this.fireObservers('putByField', field, value, element, reverse, oldElement)
81
88
  }
82
89
  remove(exact) {
90
+ this.handleError(null)
83
91
  let json = JSON.stringify(exact)
84
92
  for(let i = 0, l = this.list.length; i < l; i++) {
85
93
  if(JSON.stringify(this.list[i]) == json) this.list.splice(i, 1)
@@ -87,6 +95,7 @@ class ObservableList extends Observable {
87
95
  this.fireObservers('remove', exact)
88
96
  }
89
97
  removeByField(field, value, oldElement) {
98
+ this.handleError(null)
90
99
  let json = JSON.stringify(value)
91
100
  for(let i = 0, l = this.list.length; i < l; i++) {
92
101
  if(JSON.stringify(this.list[i][field]) == json) {
@@ -99,8 +108,9 @@ class ObservableList extends Observable {
99
108
  this.fireObservers('removeByField', field, value, oldElement)
100
109
  }
101
110
  removeBy(fields) {
111
+ this.handleError(null)
102
112
  let jsonf = []
103
- for(var k in fields) {
113
+ for(let k in fields) {
104
114
  jsonf.push([k, JSON.stringify(fields[k])])
105
115
  }
106
116
  for(let i = 0, l = this.list.length; i < l; i++) {
@@ -118,6 +128,7 @@ class ObservableList extends Observable {
118
128
  }
119
129
 
120
130
  update(exact, element) {
131
+ this.handleError(null)
121
132
  let json = JSON.stringify(exact)
122
133
  for(let i = 0, l = this.list.length; i < l; i++) {
123
134
  if(JSON.stringify(this.list[i]) == json) this.list.splice(i, 1, element)
@@ -125,6 +136,7 @@ class ObservableList extends Observable {
125
136
  this.fireObservers('update', exact, element)
126
137
  }
127
138
  updateByField(field, value, element) {
139
+ this.handleError(null)
128
140
  let json = JSON.stringify(value)
129
141
  for(let i = 0, l = this.list.length; i < l; i++) {
130
142
  if(JSON.stringify(this.list[i][field]) == json) this.list.splice(i, 1, element)
@@ -132,6 +144,7 @@ class ObservableList extends Observable {
132
144
  this.fireObservers('updateByField', field, value, element)
133
145
  }
134
146
  updateBy(fields, element) {
147
+ this.handleError(null)
135
148
  let jsonf = []
136
149
  for(const k in fields) {
137
150
  jsonf.push([k, JSON.stringify(fields[k])])
@@ -17,6 +17,7 @@ class ObservableValue extends Observable {
17
17
  }
18
18
 
19
19
  set(value) {
20
+ this.handleError(null)
20
21
  if(value === this.value) return;
21
22
  try {
22
23
  if (JSON.stringify(value) == JSON.stringify(this.value)) return;
@@ -35,7 +36,7 @@ class ObservableValue extends Observable {
35
36
  }
36
37
  unbindProperty(object, property) {
37
38
  for(let i = 0; i < this.properties.length; i++) {
38
- var prop = this.properties[i]
39
+ let prop = this.properties[i]
39
40
  if(prop[0] == object && prop[1] == property) {
40
41
  this.properties.splice(i,1)
41
42
  if(this.isUseless()) this.dispose()
@@ -51,8 +52,8 @@ class ObservableValue extends Observable {
51
52
  if(this.savedError !== undefined) object[property] = this.savedError
52
53
  }
53
54
  unbindErrorProperty(object, property) {
54
- for(var i = 0; i < this.errorProperties.length; i++) {
55
- var prop = this.errorProperties[i]
55
+ for(let i = 0; i < this.errorProperties.length; i++) {
56
+ let prop = this.errorProperties[i]
56
57
  if(prop[0] == object && prop[1] == property) {
57
58
  this.errorProperties.splice(i,1)
58
59
  if(this.isUseless()) this.dispose()
@@ -65,7 +66,7 @@ class ObservableValue extends Observable {
65
66
  handleError(error) {
66
67
  this.savedError = error
67
68
  let handled = super.handleError(error)
68
- for(var [object, property] of this.errorProperties) {
69
+ for(let [object, property] of this.errorProperties) {
69
70
  handled = true
70
71
  object[property] = error
71
72
  }
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "supports-color": "^7.2.0"
22
22
  },
23
23
  "directories": {},
24
- "license": "MIT",
24
+ "license": "BSD-3-Clause",
25
25
  "main": "index.js",
26
26
  "browsernpm ": "browser.js",
27
27
  "maintainers": [
@@ -35,6 +35,6 @@
35
35
  "scripts": {
36
36
  "test": "NODE_ENV=test blue-tape tests/*"
37
37
  },
38
- "version": "0.4.13",
39
- "gitHead": "573a234a6c5a9525aa97894fd9b2bf67ffe1d2a4"
38
+ "version": "0.5.2",
39
+ "gitHead": "9706615162cae0a4539f2e6bd1e2d5ab5babf5cd"
40
40
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 ReactiveObserver
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.