Last active
May 7, 2019 16:58
-
-
Save brianosaurus/6407318b3d7900fb992526866664dd69 to your computer and use it in GitHub Desktop.
API ideas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Proposing this structure for getters and senders. | |
export interface Pong { | |
response: string; | |
} | |
export class Ping<TBigNumber> { | |
public static PingParams = t.type({}); | |
public statuf PongParams = t.type({ respopnse: t.string }); | |
@Getter() | |
public static async pingGetter<TBigNumber>(db: DB<TBigNumber>, params: t.TypeOf<typeof Ping.PingParams>): Promise<Pong> { | |
return { | |
response: "pong", | |
}; | |
} | |
@Sender() | |
public static async pingSender<TBigNumber>(provider: AugurProvider, params: t.TypeOf<typeof Ping.PingParams>): Promise<Pong> { | |
return Ping.PongParams.decode(provider.send(params.encode()); | |
} | |
} | |
The provider is responsible for the following operations: | |
{ subscribe, unsubscribe, send, connect, disconnect } | |
Event handlers can have a similar format | |
export PING_EVENT = "ping"; | |
export class Ping<TBigNumber> { | |
public static PongParams = t.type({ response: t.string }); | |
@HandleEvent() | |
public static async ping<TBigNumber>(params: any): Promise<Pong> { | |
return Ping.PongParams.decode(params); | |
} | |
} |
What does the caller look like? What are the imports needed? Is each getter encapsulated with request, response and getter?
something like
const connector = new AugurConnector(...)
const ping = new Ping();
const param = new ping.pingParam()
const response: ping.PongParams = ping.Sender(connector, param);
I think the invocation will be more like
const response = API.send(Ping.PING_REQ, new Ping.PingParams({...});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This format looks fine to me. Personally, I like
Connector
orConnection
better thanProvider
. I can't really think of any other better names at the moment.