-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor object model to support friendlier REPL interactions #177
Conversation
Much, much better! 👍 |
Seeing some incompatible array/buffer calls, but no accessor complaints in my flow |
I added a line to the .flowconfig to enable "unsafe" getters/setters. Flow doesn't trust them by default since they can be side effecting. |
btw, my note above about whether the expanded statement bodies were a good idea was mostly because I was considering whether to make a more general "resolve object" interface, which could be backed by e.g. a Datastore instance (or even a stream to a remote node). The problem there is that you'd need the interface to be async, which is more awkward to use at the repl, etc. I'm pretty fine with the expanded bodies as they are now, I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, that's a lot of refactoring! Did you use the jetbrains refactoring features?
*/ | ||
function setEquals<T> (a: Set<T>, b: Set<T>): boolean { | ||
if (a.size !== b.size) return false | ||
for (const elem of a.values()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh I guess you can use const
instead of let
because it's scoped to inside, neat
return this.publisher | ||
} | ||
|
||
return this.body.statements[0].source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the semantics of this, don't think we have a good way to frame it so I guess this is fine for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I just copied the concat implementation for this https://github.com/mediachain/concat/blob/c27c216d777f7fa8ce96c96244e65829191023fb/mc/query/stmt.go#L62
|
||
constructor (contents: {object: string, refs?: Array<string>, deps?: Array<string>, tags?: Array<string>}) { | ||
super() | ||
this.objectRef = contents.object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess object
isn't actually a reserve word but it sure feels like it
expandObjects (source: Map<string, Object>): StatementBody { | ||
const object = source.get(this.objectRef) | ||
if (object == null) { | ||
// FIXME: should we just return the un-expanded body instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depends on our treatment of "naked"/"uninflated" objects/statements, I'm inclined to say "yes" but right now we should expect to always have the objects in sane conditions
heh, yeah I've been using intellij since they added flow support; it makes crap like this so much easier. |
This branch changes how we internally represent and interact with statements in the aleph code. Most of the existing code operated on the
StatementMsg
type, which is the unmarshaled protobuf as a JS object. This led to lots of tedious and error-prone cases around theoneof
fields, and made for cryptic and unfriendly output for queries at the REPL, etc.So this branch adds a
Statement
class, which is convertible to/from the protobuf form, and which has some handy helper methods that were formerly free functions (e.g.statementSource
is now.source()
). Each type of statement body gets its own subclass, and you can useinstanceof
checks to figure out which is which if you need to, although hopefully most of what you want will be available on the mainStatement
object which will paper over the details.A bonus of having classes is that it's easier to define a custom
.inspect()
method, which lets us override the default printed representation at the REPL and inconsole.log
s.I also changed the
.remoteQuery
method to unwrap the query results from the protobuf's they're delivered in, which, combined with the custom.inspect
methods, makes for a much nicer REPL experience.namespace list query (old):
namespace list query (new):
Combined with the custom
.inspect
methods, it makes fetching a statement (and its data) much nicer. TheremoteQueryWithData
method returns a statement with a special "expanded" body, and has a nice clean representation at the console:Anyway, there's still some cleanup and testing to do here; a few places still work with the "raw" protobuf messages instead of the new classes, and I haven't tested all the new code yet.
TODO:
.objectIds
) on statements with plain methods, since flow doesn't like getters