statebus 6.1.22 → 6.1.23
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/client.js +56 -8
- package/package.json +1 -1
- package/statebus.js +3 -3
package/client.js
CHANGED
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
var has_prefix = new RegExp('^' + preprefix)
|
|
64
64
|
var is_absolute = /^https?:\/\//
|
|
65
65
|
var subscriptions = {}
|
|
66
|
+
var put_counter = 0
|
|
66
67
|
//if (url[url.length-1]=='/') url = url.substr(0,url.length-1)
|
|
67
68
|
function add_prefix (key) {
|
|
68
69
|
return is_absolute.test(key) ? key : preprefix + key }
|
|
@@ -73,21 +74,66 @@
|
|
|
73
74
|
function rem_prefixes (obj) {
|
|
74
75
|
return bus.translate_keys(bus.clone(obj), rem_prefix) }
|
|
75
76
|
|
|
77
|
+
|
|
78
|
+
var puts = new Map()
|
|
79
|
+
function enqueue_put (url, body) {
|
|
80
|
+
var id = put_counter++
|
|
81
|
+
puts.set(id, {url: url, body: body, id: id})
|
|
82
|
+
send_put(id)
|
|
83
|
+
}
|
|
84
|
+
function send_put (id) {
|
|
85
|
+
try {
|
|
86
|
+
puts.get(id).status = 'sending'
|
|
87
|
+
braid_fetch(
|
|
88
|
+
puts.get(id).url,
|
|
89
|
+
{
|
|
90
|
+
method: 'put',
|
|
91
|
+
headers: {
|
|
92
|
+
'content-type': 'application/json',
|
|
93
|
+
'put-order': id,
|
|
94
|
+
},
|
|
95
|
+
body: puts.get(id).body
|
|
96
|
+
}
|
|
97
|
+
).then(function (res) {
|
|
98
|
+
if (res.status !== 200)
|
|
99
|
+
console.error('Server gave error on PUT:',
|
|
100
|
+
e, 'for', puts.get(id).body)
|
|
101
|
+
else
|
|
102
|
+
console.log('Successful put!', puts.get(id).body)
|
|
103
|
+
puts.delete(id)
|
|
104
|
+
}).catch(function (e) {
|
|
105
|
+
console.error('Error on PUT, waiting...', puts.get(id).url)
|
|
106
|
+
puts.get(id).status = 'waiting'
|
|
107
|
+
// console.error('Error on PUT:', e, 'for', puts.get(id).body)
|
|
108
|
+
// puts.delete(id)
|
|
109
|
+
})
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error('Error on PUT, waiting...', puts.get(id).url)
|
|
112
|
+
puts.get(id).status = 'waiting'
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function retry_put (id) {
|
|
116
|
+
setTimeout(function () {send_put(id)}, 1000)
|
|
117
|
+
}
|
|
118
|
+
function send_all_puts () {
|
|
119
|
+
puts.keys().forEach(function (id) {
|
|
120
|
+
if (puts.get(id).status === 'waiting') {
|
|
121
|
+
console.log('Sending waiting put', id)
|
|
122
|
+
send_put(id)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
76
127
|
bus(prefix).to_save = function (obj, t) {
|
|
77
128
|
bus.save.fire(obj)
|
|
78
129
|
|
|
130
|
+
enqueue_put(url + rem_prefix(obj.key),
|
|
131
|
+
JSON.stringify(obj.val))
|
|
79
132
|
// var x = {save: obj}
|
|
80
133
|
// if (t.version) x.version = t.version
|
|
81
134
|
// if (t.parents) x.parents = t.parents
|
|
82
135
|
// if (t.patch) x.patch = t.patch
|
|
83
136
|
// if (t.patch) x.save = rem_prefix(x.save.key)
|
|
84
|
-
|
|
85
|
-
braid_fetch(url + rem_prefix(obj.key),
|
|
86
|
-
{
|
|
87
|
-
method: 'put',
|
|
88
|
-
'content-type': 'application/json',
|
|
89
|
-
body: JSON.stringify(obj.val)
|
|
90
|
-
})
|
|
91
137
|
}
|
|
92
138
|
|
|
93
139
|
bus(prefix).to_fetch = function (key, t) {
|
|
@@ -140,6 +186,7 @@
|
|
|
140
186
|
'color: blue')
|
|
141
187
|
reconnect_attempts = 0
|
|
142
188
|
subscriptions[key].status = 'connected'
|
|
189
|
+
send_all_puts()
|
|
143
190
|
}
|
|
144
191
|
|
|
145
192
|
// Return the update
|
|
@@ -644,7 +691,8 @@
|
|
|
644
691
|
for (var k in this.props)
|
|
645
692
|
if (this.props.hasOwnProperty(k))
|
|
646
693
|
new_props[k] = this.props[k]
|
|
647
|
-
if (this.state.value)
|
|
694
|
+
if (this.state.hasOwnProperty('value'))
|
|
695
|
+
new_props.value = this.state.value
|
|
648
696
|
new_props.onChange = this.onChange
|
|
649
697
|
return element(new_props)
|
|
650
698
|
}
|
package/package.json
CHANGED
package/statebus.js
CHANGED
|
@@ -2179,13 +2179,13 @@
|
|
|
2179
2179
|
if (a_array !== b_array) return ' = ' + JSON.stringify(b)
|
|
2180
2180
|
if (a_array) {
|
|
2181
2181
|
if (a.length === b.length-1
|
|
2182
|
-
&&
|
|
2183
|
-
return '.push(' +JSON.stringify(b[b.length]) + ')'
|
|
2182
|
+
&& deep_equals(a[a.length-1], b[b.length-2])) {
|
|
2183
|
+
return '.push(' +JSON.stringify(b[b.length-1]) + ')'
|
|
2184
2184
|
}
|
|
2185
2185
|
for (var i=0; i < a.length; i++) {
|
|
2186
2186
|
var tmp = sorta_diff (a[i], b[i])
|
|
2187
2187
|
if (tmp)
|
|
2188
|
-
return '['+i+']
|
|
2188
|
+
return '['+i+']'+tmp
|
|
2189
2189
|
}
|
|
2190
2190
|
return null
|
|
2191
2191
|
}
|