Closed karth295 closed 7 years ago
Wow! Thank you for discovering this!
I've never investigated strict mode. One downside is that we currently return the value of the property upon set, so you can do things like this:
var x = sb.x = 3
x // 3
But with strict mode, this will end up being impossible:
var x = sb.x = null
x // can't be null. will have to be true instead.
I'm considering doing the strict behavior only if strict mode is set. But maybe it's not worthwhile to introduce the inconsistency in behavior. I'm not sure.
Fixed.
For now, I've made strict and non-strict mode behavior inconsistent. But I'm not fully confident in this decision. It would be good to examine how valuable it is to be able to say var x = sb.x = 3
, and whether it outweighs the cost of inconsistency.
It's also possible that we should re-use the "return true on success and false on failure" semantics as "return true when a save transaction has completed successfully, and false otherwise":
bus(() => {
var result = sb["/foo"].bar = 3
})
// On initial run, sb["/foo"] hasn't loaded, so it can't alter it, and returns false
// On second run, sb["/foo"] has loaded, so it saves it,but that save hasn't completed, so it returns false
// On final run, the save is complete, so it returns true
Or if the server's bus('/foo').to_fetch
function calls save.abort(o)
, then the save would always return false
, because it was aborted.
We don't yet have enough information propagating between nodes to know when a transaction has completed, however. So this would only be possible in the future.
Uncaught TypeError: 'set' on proxy: trap returned falsish for property '/foo'
Proxy.set() must return
true
to indicate success: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/set