-
Notifications
You must be signed in to change notification settings - Fork 111
Conversation
Latest commit adds a |
733dee3
to
8aafd19
Compare
@fabioberger I removed the WIP tag and this PR is ready for review. I still expect that there will be some discussion about naming, interface design, and project structure. |
const zeroExMesh: ZeroExMesh; | ||
} | ||
|
||
/** |
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.
@fabioberger We should probably generate docs for the TypeScript bindings similar to what we did for the TypeScript RPC client. Can you point me in the right direction? Alternatively we could do that in a separate PR since this is already pretty big.
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.
You'll need "@0x/ts-doc-gen": "^0.0.16",
dep and a command:
"scripts": {
"docs:md": "ts-doc-gen --sourceDir=./src --output=${npm_package_config_docsPath}"
},
"config": {
"docsPath": "../../../docs/json_rpc_clients/typescript"
},
Just change the docsPath
to where you want the MD generated to and it should work 👍
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.
👍@fabioberger just added this. Mind eyeballing the docs to make sure everything looks right?
I know there's not a lot of tests here. I'm planning to write integration tests in a separate PR. The way it will work is that we'll spin up a few nodes on a local network and confirm that they can connect and share orders with one another. It will involve coordinating between some native Go nodes and some that are running in a headless browser. In the meantime, examples/browser can serve as a sort of ad hoc integration test. |
"webpack-cli": "^3.3.7" | ||
}, | ||
"dependencies": { | ||
"@0x/mesh-browser": "./../../browser/" |
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.
Right now the example uses a local copy of the TypeScript bindings. I'll update this to use the actual version once we have published the package on NPM.
loadEventName = "0xmeshload" | ||
// orderEventsBufferSize is the buffer size for the orderEvents channel. If | ||
// the buffer is full, any additional events won't be processed. | ||
orderEventsBufferSize = 100 |
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.
Any reason not to bump this up a bit higher?
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.
Increasing orderEventsBufferSize
reduces the chance of order events being missed but increases memory usage. I think 100 is a decent starting point but we can adjust it if needed. The channel should never get that full if an orderEventsHandler
is set.
signedOrder: MeshSignedOrder; | ||
kind: RejectedOrderKind; | ||
status: RejectedOrderStatus; | ||
} |
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.
These are all duplicated from @0x/mesh-rpc-client
. Any ideas on how to avoid that? I can't think of any without creating a TS monorepo within this repo...
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 can't think of anything else either. I'm not sure if it's worth the overhead of using a TS monorepo here. Let's copy it manually for now and discuss later?
browser/ts/index.ts
Outdated
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
function meshSignedOrderToSignedOrder(meshSignedOrder: MeshSignedOrder): SignedOrder { |
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.
Why you're calling MeshSignedOrder
we call StringifiedSignedOrder
in mesh-rpc-client
. Thoughts on standardizing?
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.
Hmm... StringifiedSignedOrder
is an okay name in this case because all the types are strings. However, I want to pick a name that highlights the pattern of converting between Go types and TypeScript types. I'm thinking that there will be other type conversions in the future and not just string
to BigNumber
. I can't think of a good name to cover the use cases in both mesh-rpc-client
and mesh-browser
. Maybe something like BasicSignedOrder
?
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.
My vote would perhaps be StringifiedSignedOrder
for now, and if there are other types involved in the future, changing it then. Don't feel too strongly about this though, so we can also leave it 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.
I'm going to go with WrapperSignedOrder
, WrapperOrderEvent
, WrapperValidationResults
, etc. to more closely match the fact that these are types exposed by MeshWrapper
that might need further conversion. This is what I was originally trying to show with the Mesh*
prefix but I feel that name was too confusing. Happy to re-evaluate later.
Co-Authored-By: Fabio B <me@fabioberger.com>
Co-Authored-By: Fabio B <me@fabioberger.com>
…-mesh into feature/typescript-bindings
Fixes #298.
This PR adds TypeScript bindings and an npm package for using Mesh in the browser. The Wasm bytecode is embedded in the package itself which makes it really easy to import and use. It also adds an example of how to import and use the TypeScript bindings.
Here's a breakdown of the directory structure and key files:
@0x/mesh-browser
.0x-mesh/core
and adds everything we need to the global scope.ArrayBuffer
.@0x/mesh-browser
package in a browser-based application. It uses TypeScript and webpack.I'm planning to clean this up and document it in a README, but for now here are the steps for running the example:
yarn install && yarn build
.yarn install && yarn build
.goexec 'http.ListenAndServe(":8000", http.FileServer(http.Dir("./examples/browser/dist")))'