npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

electron-happy-ipc

v1.0.0-beta

Published

async request for ipc.

Downloads

6

Readme

electron-happy-ipc

Github Actions Testcodecov.io

electron-happy-ipc 基于 electron IPC 进行二次封装,使 IPC 的方式像 http 请求一样方便简单。

Why it

在 electron 中,如果使用要使用 node API,则需要使用 Renderer ProcessMain Process 发起通信(IPC),然后 Main Process 中处理相关逻辑。

而 IPC 通信则需要两个进程都需要先监听一个事件,在 SPA 带有生命周期的场景中,Renderer Process 还需要监听、销毁等繁琐操作。且代码可读性差也不易于后期维护。

Quick start

  1. install

    yarn add electron-happy-ipc
    #或者
    npm install -S electron-happy-ipc
  2. import

    1. 在 Main Process 中引用,类似 Koa router 的使用方式,作为 controller 方式管理
    2. 在 Renderer Process 中引用,类似于 axios 使用方式
    • Main Process

      import server from 'electron-happy-ipc/server'
           
      server.use('test', async (ctx, data) => {
        // data => { a: 1 }  from Renderer Process
        const result = await doSomething(data)
        ctx.reply(['1', '2', '3'])
      })
    • Renderer Process

      这里以 react 组件举例说明

      import React, { useState, useEffect } from 'react'
      import request from 'electron-happy-ipc/request'
           
      export default function IpcTest () {
        const [list, setList] = useState([])
               
        useEffect(() => {
          init()
        }, [])
             
        const init = async () => {
          // request 取代 ipcRenderer.send 和 ipcRenderer.on
          const result = await request('test', { a: 1 })
          // result => ['1', '2', '3'] from Main Process
          setList(result)
        }
      }

API

cover

boolean 可选

默认 false。多次调用,避免后续处理逻辑执行多次。

比如发起一个分页请求,点击第 2 页后,紧接着又点击了第 3 页,假如 第 2 页 的请求执行时间大于 第 3 页请求执行时间,那第 3 页的响应会先被 resolve,接着第 2 页的响应又被 resolve 了。

结果就是当前要展示第 3 页,但数据却是第 2 页的。

注意:设置 cover 仍会向 Main Process 发送两次通信

const init = async () => {
  try {
    const result = await request({
    url: 'test',
    data: { a: 1 },
    replace: true
  })
  console.log(result)
  } catch (err) {
    // 第一次调用 reject
  }
}

init() // 假如 init 需要 500ms 才会返回
init() // 紧接着再次调用,上一次的 init 会立刻 reject。
timeout

number 可选

单位:ms(毫秒)

默认。设置此次请求的超时时间。

主要当传递 0 时,不生效。

全局 API

setConfig

设置全局配置。

import request, { setConfig } from 'electron-happy-ipc/request'

 // 所有的 request 都会生效
setConfig({
  replace: true,
  timeout: 1000 * 60
})

// 还原全局设置
setConfig()

License

MIT