Skip to content
Discussion options

You must be logged in to vote

This is similar to the ideas in Comlink; it's sort of a proxy for sending events.

You can definitely do this in user-land, and perhaps XState can provide (opt-in) helper functions to help you do this:

function createProxy(service) {
  const handler = {
    get(target, propKey, receiver) {
      return (payload) => {
        service.send(propKey, payload);
      };
    }
  };

  return new Proxy(service, handler);
}

const serviceProxy = createProxy(someService);

serviceProxy.TOGGLE()
// ... etc.

Example: https://codesandbox.io/s/xstate-proxy-example-62w2i?file=/src/index.js


There are a couple of issues with this approach, though:

  • Methods (which are conceptually the same as sending mess…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@serhiipalash
Comment options

@davidkpiano
Comment options

@serhiipalash
Comment options

@davidkpiano
Comment options

@serhiipalash
Comment options

Answer selected by serhiipalash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants