1.0.0 • Published 2 years ago

@codingruo/zod-bus v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

zod-bus

Gives you type-safe message passing (using Zod!) between two different environments.

// protocol.ts

const protocol = createMessageProtocol({
  events: {
    LOG_IN: {
      username: z.string(),
      password: z.string(),
    },
    LOG_OUT: {},
  },
});

// iframe.ts

// Type safe sender
const sendToParent = protocol.createHandler(window.parent.postMessage);

// Type safe receiver
const handleParentEvent = protocol.createHandler((event) => {
  console.log(event);
});

window.addEventListener("message", (event) => {
  handleParentEvent(event.data);
});

Installation

pnpm add @codingruo/zod-bus

npm i @codingruo/zod-bus

yarn add @codingruo/zod-bus

Usage

1.0.0

2 years ago

0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago