Playground recipe · boundary

Keep local state off the wire.

Add whatever local bookkeeping the instance needs. The transport surface still emits exactly type and data.

js-message works with bundlers and without a bundler.

Bundlers resolve the bare js-message import normally. Native browser ESM resolves it through a standard import map, with no build or transpilation step.

Complete source

import Message from 'js-message';

const message = new Message({
    type: 'job.ready',
    data: { id: 'job_8' }
});

message.transport = 'local only';

console.log('instance', message);
console.log('wire', message.JSON);

What to inspect

  • The live instance includes transport.
  • The wire JSON contains only type and data.
  • toJSON() enforces the same boundary for native serialization.