Skip to content
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

Open
chase-moskal opened this issue Feb 1, 2019 · 2 comments
Open

Refactor callee and permissions, move events under topics #5

chase-moskal opened this issue Feb 1, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@chase-moskal
Copy link
Owner

chase-moskal commented Feb 1, 2019

const host = new crosscall.Host({

  // NEW CALLEE
  callee: {
    exampleTopic: {
      methods: {
        async exampleMethodAlpha(a) { return a + 1 },
        async exampleMethodBravo(a, b) { return a + b }
      },
      events: {
        exampleEvent: {
          listen(listener) {
            window.addEventListener("explosion", listener)
          },
          unlisten(listener) {
            window.removeEventListener("explosion", listener)
          }
        }
      }
    }
  },

  // NEW PERMISSIONS
  permissions: [{
    origin: /^http:\/\/localhost:8080$/,
    allowed: {
      exampleTopic: {
        methods: ["exampleMethodAlpha", "exampleMethodBravo"].
        events: ["exampleEvent"]
      }
    }
  }]
})
@chase-moskal
Copy link
Owner Author

chase-moskal commented Feb 1, 2019

the following is unacceptable

const {callable} = await client.callable
const {exampleTopic} = callable.exampleTopic
exampleTopic.methods.doCoolThing()
exampleTopic.events.coolThing.listen(() => {})

having the methods and events objects under the topic is gross

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

@chase-moskal
Copy link
Owner Author

chase-moskal commented Oct 21, 2019

bigger brain

const 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
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant