Skip to content
Snippets Groups Projects
Commit 4019a816 authored by yamadapc's avatar yamadapc
Browse files

Initial implementation of API method codegen

Doesn't mess with the exported API. Adds a `lib/api-from-methods` module
exporting all API methods that use the
`this.send(apiName, options, callback)` scheme.

The generated functions work as follows. For every method in
`methods.json`, two functions are generated:

- `camelCaseMethodWith`
- `camelCaseMethod`

The usages are:

```javascript
api.camelCaseMethodWith(options, callback);
```

And:
```javascript
api.camelCaseMethod(param1, param2, callback);
```

`options` currently holds parameters with their names generated from the
source `lib/api.js` variable names. For example:

```javascript
api.getBlockWith({
  blockNum: 1, // <- because `lib/api.js` called the variable `blockNum`
}, function (err, operation) {
  console.log(err, operation);
});

api.getBlock(1, function (err, operation) {
  console.log(err, operation);
});
```

Further improvements could be made to the method data and generated code. Namely:
- It'll require a `json-loader` or way to require `.json` files on
  browser bundlers
- It doesn't handle #22
- When there's no error but the `data.id` mismatches the iterator, the
  callback isn't called; this is a weird design decision

This closes #23.
parent 2521e3e7
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment