lodash#pull JavaScript Examples

The following examples show how to use lodash#pull. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: listen.js    From holo-schedule with MIT License 5 votes vote down vote up
browser.runtime.onConnect.addListener(port => {
  console.log('[background/ports]on connect', port.name)
  if (port.name !== 'port') return

  ports.push(port)

  Object.values(portByName).forEach($port => {
    $port.onConnect($port)
  })

  // eslint-disable-next-line no-param-reassign
  port.originalPostMessage = port.postMessage
  // eslint-disable-next-line no-param-reassign
  port.postMessage = message => {
    try {
      port.originalPostMessage(browser.isChrome ? message : JSON.parse(JSON.stringify(message)))
    } catch (err) {
      console.error(err)
    }
  }

  port.onMessage.addListener(async ({ isResponse, id, name, message }) => {
    if (isResponse) {
      // Not supported
      return
    }

    if (!portByName[name]) {
      console.log(`[background/ports]failed to find port ${name}`)
      return
    }

    try {
      const response = await portByName[name].onMessage(message)
      port.postMessage({ isResponse: true, id, name, message: response })
    } catch (error) {
      port.postMessage({ isResponse: true, id, name, message: error.message, isError: true })
    }
  })

  port.onDisconnect.addListener(() => pull(ports, port))
})