1.0.1 • Published 3 years ago

postis-plus v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

postis-plus

the package base on postis.

Install

npm i postis-plus --save

Usage

Parent HTML which contains an iframe:

import postisPlus from "postis-plus";
const targetWindow = document.querySelectorAll("iframe")[0].contentWindow;

const transport = postisPlus({
  window: targetWindow,
  scope: "scope-for-message-changing-to-avoid-overlapping"
});

// addListener event of 'event'
transport.on('event', ({ name, data }) => {
  switch (name) {
    case 'eventName':
      console.log(data)
      break
  }
})


// addListener event of 'resolve'
transport.on('resolve', ({ name, data }, handler) => {
  switch (name) {
    case 'eventName':
      console.log(data)

      ...
      handler(res)
      break
  }
})

In embedded child iframe:

import postisPlus from "postis-plus";
const targetWindow = window.parent;

const transport = postisPlus({
  window: targetWindow,
  scope: "scope-for-message-changing-to-avoid-overlapping"
});

// emit event of 'event'
transport.sendEvent({
  name: 'eventName',
  data: data
})

// emit event of 'resolve'
transport.sendResolve({ name: 'eventName',data: data })
.then((res) => {
  console.log(res)
})
1.0.1

3 years ago

1.0.0

3 years ago