statebus 7.0.10 → 7.0.12
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-library.js +7 -6
- package/extras/tests.js +19 -19
- package/package.json +1 -1
- package/server-library.js +7 -5
- package/statebus.js +3 -0
package/client-library.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
var websocket_prefix = (clientjs_option('websocket_path')
|
|
3
3
|
|| '_connect_to_statebus_')
|
|
4
4
|
|
|
5
|
-
var react_render = ReactDOM.render
|
|
6
5
|
// make_client_statebus_maker()
|
|
7
6
|
window.bus = window.statebus()
|
|
8
7
|
bus.label = 'bus'
|
|
@@ -183,7 +182,7 @@
|
|
|
183
182
|
headers: {accept: 'application/json'},
|
|
184
183
|
signal: aborter.signal
|
|
185
184
|
}
|
|
186
|
-
).andThen( function (
|
|
185
|
+
).andThen( function (new_version) {
|
|
187
186
|
// New update received!
|
|
188
187
|
if (subscriptions[key].status === 'connecting') {
|
|
189
188
|
console.log('%c[*] opened ' + key,
|
|
@@ -196,7 +195,7 @@
|
|
|
196
195
|
// Return the update
|
|
197
196
|
t.return({
|
|
198
197
|
key: key,
|
|
199
|
-
val: add_prefixes(JSON.parse(
|
|
198
|
+
val: add_prefixes(JSON.parse(new_version.body))
|
|
200
199
|
})
|
|
201
200
|
}).catch( function (e) {
|
|
202
201
|
if (subscriptions[key].status === 'aborted') {
|
|
@@ -831,9 +830,10 @@
|
|
|
831
830
|
// We create special functions for INPUT and TEXTAREA, because they
|
|
832
831
|
// have to do extra work to maintain the cursor when we use statebus
|
|
833
832
|
// instead of React's setState() for state updates.
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
833
|
+
if (window.React && !React.createClass && window.createReactClass) {
|
|
834
|
+
bus.libs.react17.input = make_fixed_textbox('input')
|
|
835
|
+
bus.libs.react17.textarea = make_fixed_textbox('textarea')
|
|
836
|
+
}
|
|
837
837
|
function autodetect_args (func) {
|
|
838
838
|
if (func.args) return
|
|
839
839
|
|
|
@@ -981,6 +981,7 @@
|
|
|
981
981
|
return widge(props, children)
|
|
982
982
|
}
|
|
983
983
|
|
|
984
|
+
// var react_render = ReactDOM.render
|
|
984
985
|
// window.users_widgets = users_widgets
|
|
985
986
|
// function load_widgets () {
|
|
986
987
|
// for (var w in users_widgets) {
|
package/extras/tests.js
CHANGED
|
@@ -1122,22 +1122,22 @@ function setup_servers () {
|
|
|
1122
1122
|
c.ws_mount('/*', 'statei://localhost:' + port)
|
|
1123
1123
|
|
|
1124
1124
|
s.set({key: 'users',
|
|
1125
|
-
val: [ {link: '
|
|
1126
|
-
{link: '
|
|
1127
|
-
{link: '
|
|
1128
|
-
s.set({ key: '
|
|
1125
|
+
val: [ {link: '@1'},
|
|
1126
|
+
{link: '@2'},
|
|
1127
|
+
{link: '@3'} ] })
|
|
1128
|
+
s.set({ key: '@1', val: {
|
|
1129
1129
|
name: 'mike',
|
|
1130
1130
|
email: 'toomim@gmail.com',
|
|
1131
1131
|
admin: true,
|
|
1132
1132
|
pass: '$2a$10$Ti7BgAZS8sB0Z62o2NKsIuCdmU3q9xP7jexVccTcG19Y8qpBpl/1y'
|
|
1133
1133
|
}})
|
|
1134
|
-
s.set({ key: '
|
|
1134
|
+
s.set({ key: '@2', val: {
|
|
1135
1135
|
name: 'j',
|
|
1136
1136
|
email: 'jtoomim@gmail.com',
|
|
1137
1137
|
admin: true,
|
|
1138
1138
|
pass: '$2a$10$Ti7BgAZS8sB0Z62o2NKsIuCdmU3q9xP7jexVccTcG19Y8qpBpl/1y'
|
|
1139
1139
|
}})
|
|
1140
|
-
s.set({ key: '
|
|
1140
|
+
s.set({ key: '@3', val: {
|
|
1141
1141
|
name: 'boo',
|
|
1142
1142
|
email: 'boo@gmail.com',
|
|
1143
1143
|
admin: false,
|
|
@@ -1260,7 +1260,7 @@ test(function create_account (done) {
|
|
|
1260
1260
|
// Log out
|
|
1261
1261
|
delay(600, () => {
|
|
1262
1262
|
assert(cu.val.logged_in)
|
|
1263
|
-
assert(cu.val.user.link === '
|
|
1263
|
+
assert(cu.val.user.link === '/@bob')
|
|
1264
1264
|
|
|
1265
1265
|
log('Now let\'s log out!')
|
|
1266
1266
|
cu.val.logout = true; c.set(cu)
|
|
@@ -1276,7 +1276,7 @@ test(function create_account (done) {
|
|
|
1276
1276
|
|
|
1277
1277
|
delay(600, () => {
|
|
1278
1278
|
assert(cu.val.logged_in)
|
|
1279
|
-
assert(cu.val.user.link === '
|
|
1279
|
+
assert(cu.val.user.link === '/@bob')
|
|
1280
1280
|
done()
|
|
1281
1281
|
})
|
|
1282
1282
|
})
|
|
@@ -1521,7 +1521,7 @@ if (false) {
|
|
|
1521
1521
|
// Logged in as mike
|
|
1522
1522
|
[(u.logged_in
|
|
1523
1523
|
&& u.user.name === 'mike'
|
|
1524
|
-
&& u.user.key === '
|
|
1524
|
+
&& u.user.key === '/@1'
|
|
1525
1525
|
|
|
1526
1526
|
// We can see our email
|
|
1527
1527
|
&& u.user.email
|
|
@@ -1547,7 +1547,7 @@ if (false) {
|
|
|
1547
1547
|
// Logged in as j
|
|
1548
1548
|
[(u.logged_in
|
|
1549
1549
|
&& u.user.name === 'j'
|
|
1550
|
-
&& u.user.key === '
|
|
1550
|
+
&& u.user.key === '/@2'
|
|
1551
1551
|
|
|
1552
1552
|
// We can see j's email
|
|
1553
1553
|
&& u.user.email
|
|
@@ -1564,10 +1564,10 @@ if (false) {
|
|
|
1564
1564
|
c('/current_user').on_set = function (o) {
|
|
1565
1565
|
//if (o.user && o.user.name === 'j') {
|
|
1566
1566
|
// log(s.userbus.deps('/current_user'))
|
|
1567
|
-
// log(s.userbus.deps('
|
|
1567
|
+
// log(s.userbus.deps('/@2'))
|
|
1568
1568
|
//}
|
|
1569
1569
|
}
|
|
1570
|
-
c('
|
|
1570
|
+
c('/@*').on_set = function (o) {
|
|
1571
1571
|
//log('-> Got new', o.key, o.email ? 'with email' : '')
|
|
1572
1572
|
}
|
|
1573
1573
|
c('/current_user').on_set = function (o) {
|
|
@@ -1575,9 +1575,9 @@ if (false) {
|
|
|
1575
1575
|
}
|
|
1576
1576
|
c(function loop () {
|
|
1577
1577
|
u = c.get('/current_user')
|
|
1578
|
-
user1 = c.get('
|
|
1579
|
-
user2 = c.get('
|
|
1580
|
-
user3 = c.get('
|
|
1578
|
+
user1 = c.get('/@1')
|
|
1579
|
+
user2 = c.get('/@2')
|
|
1580
|
+
user3 = c.get('/@3')
|
|
1581
1581
|
var st = states()
|
|
1582
1582
|
|
|
1583
1583
|
if (phase===1)
|
|
@@ -1613,12 +1613,12 @@ if (false) {
|
|
|
1613
1613
|
var cu = c.get('/current_user')
|
|
1614
1614
|
c.set({key: '/current_user', val: {create_account: {name: 'a', pass: 'a'}}})
|
|
1615
1615
|
c.set({key: '/current_user', val: {login_as: {name: 'a', pass: 'a'}}})
|
|
1616
|
-
var a_closet = c.get('
|
|
1617
|
-
var a_private = c.get('
|
|
1616
|
+
var a_closet = c.get('/@a/foo')
|
|
1617
|
+
var a_private = c.get('/@a/private/foo')
|
|
1618
1618
|
|
|
1619
1619
|
delay(400, () => {
|
|
1620
|
-
c.set({key: '
|
|
1621
|
-
c.set({key: '
|
|
1620
|
+
c.set({key: '/@a/foo', _: 3})
|
|
1621
|
+
c.set({key: '/@a/private/foo', _: 4})
|
|
1622
1622
|
})
|
|
1623
1623
|
|
|
1624
1624
|
// User A can see it
|
package/package.json
CHANGED
package/server-library.js
CHANGED
|
@@ -2054,7 +2054,9 @@ function import_server (bus, make_statebus, options)
|
|
|
2054
2054
|
o.val.pass = o.val.pass && require('bcrypt-nodejs').hashSync(o.val.pass)
|
|
2055
2055
|
u.val.pass = o.val.pass || u.val.pass
|
|
2056
2056
|
|
|
2057
|
-
// //
|
|
2057
|
+
// // Allow clients to save a base64 image in the .pic field,
|
|
2058
|
+
// // which we'll convert into an image file here. (Note: removed.
|
|
2059
|
+
// // There are more elegant solutions possible now.)
|
|
2058
2060
|
// // Bug: if user changes name, this picture's url doesn't change.
|
|
2059
2061
|
// if (o.pic && o.pic.indexOf('data:image') > -1) {
|
|
2060
2062
|
// var img_type = o.pic.match(/^data:image\/(\w+);base64,/)[1]
|
|
@@ -2063,19 +2065,19 @@ function import_server (bus, make_statebus, options)
|
|
|
2063
2065
|
// // ensure that the uploads directory exists
|
|
2064
2066
|
// if (!fs.existsSync(upload_dir))
|
|
2065
2067
|
// fs.mkdirSync(upload_dir)
|
|
2066
|
-
|
|
2068
|
+
//
|
|
2067
2069
|
// // bug: users with the same name can overwrite each other's files
|
|
2068
2070
|
// u.pic = u.name + '.' + img_type
|
|
2069
2071
|
// fs.writeFile(upload_dir + u.pic, b64, {encoding: 'base64'})
|
|
2070
2072
|
// }
|
|
2071
2073
|
|
|
2072
2074
|
// For anything else, go ahead and add it to the user object
|
|
2073
|
-
var
|
|
2075
|
+
var reserved = {'key':true, 'name':true, 'pass':true}
|
|
2074
2076
|
for (var k in o.val)
|
|
2075
|
-
if (!
|
|
2077
|
+
if (!reserved.hasOwnProperty(k))
|
|
2076
2078
|
u.val[k] = o.val[k]
|
|
2077
2079
|
for (var k in u.val)
|
|
2078
|
-
if (!
|
|
2080
|
+
if (!reserved.hasOwnProperty(k) && !o.val.hasOwnProperty(k))
|
|
2079
2081
|
delete u.val[k]
|
|
2080
2082
|
|
|
2081
2083
|
master.set(u)
|
package/statebus.js
CHANGED
|
@@ -1034,6 +1034,9 @@
|
|
|
1034
1034
|
// funk.react().
|
|
1035
1035
|
//
|
|
1036
1036
|
// ...which will make it re-run with the original arg1 and arg2 .
|
|
1037
|
+
//
|
|
1038
|
+
// Each subsequent time you call f(arg1, arg2), it will change the
|
|
1039
|
+
// remembered args and re-run the funk.
|
|
1037
1040
|
function funk () {
|
|
1038
1041
|
console.assert(executing_funk === global_funk
|
|
1039
1042
|
|| executing_funk !== funk, 'Recursive funk', funk.func)
|