-
Notifications
You must be signed in to change notification settings - Fork 0
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 callee and permissions, move events under topics #5
Labels
enhancement
New feature or request
Comments
the following is unacceptable const {callable} = await client.callable
const {exampleTopic} = callable.exampleTopic
exampleTopic.methods.doCoolThing()
exampleTopic.events.coolThing.listen(() => {}) having the therefore, the following strategy is better const host = new crosscall.Host({
callee: {
methods: {
exampleDragonMethods: {
async fly(a) { return a + 1 },
async breatheFire(a, b) { return a + b },
async eatPeasants(a, b, c) { return a * b * c }
}
},
events: {
exampleKangarooEvents: {
kangarooHopped: {
listen(listener) {
window.addEventListener("kangarooHopped", listener)
},
unlisten(listener) {
window.removeEventListener("kangarooHopped", listener)
}
}
}
}
},
permissions: [{
origin: /^http:\/\/localhost:8080$/,
allowedMethods: {
exampleDragonMethods: ["fly", "breatheFire", "eatPeasants"]
},
allowedEvents: {
exampleKangarooEvents: ["kangarooHopped"]
}
}]
})
// later, on the client
const {callable} = await client.callable
const {exampleDragonMethods} = callable.methods
const {exampleKangarooEvents} = callable.events the downside is that methods and events can never share a topic, they can't live on the same object meh |
bigger brainconst host = new CrosscallHost({
exposures: [{
allowed: /^http\:\/\/localhost\:8\d{3}$/i,
forbidden: /\:8989$/i,
methods: {
dragonMethods: {
async fly(a) { return a + 1 },
async breatheFire(a, b) { return a + b },
async eatPeasants(a, b, c) { return a * b * c }
}
},
events: {
kangarooEvents: {
kangarooHopped: {
listen(listener) {
window.addEventListener("kangarooHopped", listener)
},
unlisten(listener) {
window.removeEventListener("kangarooHopped", listener)
}
}
}
}
}]
}
// later, on the client
const callable = await client.callable
const {dragonMethods} = callable.methods
const {kangarooEvents} = callable.events |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: