GithubHelp home page GithubHelp logo

krimlabs / eiphop Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 8.0 2.76 MB

A fetch like wrapper for elecron's ipc.

Home Page: https://eiphop.js.org

JavaScript 87.59% HTML 12.41%
electron ipc react redux

eiphop's People

Contributors

anis-campos avatar brumik avatar cworsley4 avatar dependabot[bot] avatar hadeeb avatar shivekkhurana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

eiphop's Issues

React - memory leak when component unmount before response.

I want to unsubscribe pending events on unmount react component because it is causing memory leak.
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Write unit and e2e tests ๐Ÿฅ

Most of the functions can be tested using unit tests.

The overall functionality however will need an electron instance and some form of e2e testing.

Study available tools to implement that. This will increase the overall quality of the project.

Improve readme doc

The current readme was a mindless copy paste from my blog post.
Create a more clear readme with that highlights the vision of this wrapper to be a fetch equivalent for electron ipc. Make installation and getting started easier.

Comments and suggestions welcome :)

Timeout issue

I noticed when an action takes some time I get an error:

WebSocket connection to 'ws://localhost:3000/sockjs-node/324/1puq2ekr/websocket' failed:
WebSocket is closed before the connection is established.

I receive the data no problem but I am getting this warning.

An example code I am using is the following:

console.log("Start");
emit('sourceGet', params).then(res => {
  console.log("End");
  setState({
    mode: 0,
    ...res
  });
});

The console output is
Start
The error mentionned
End

in SourceGet if I remove the function that takes time, the error dissapears.
The function is a nodejs addon (c++ based) so it should not intervene with eiphop.

And thanks for such a great api

Cannot read property 'dfd' of undefined

Hello,

I am using eiphop and whenever I call the emit function I get the following error:

renderer.js:111 Uncaught TypeError: Cannot read property 'dfd' of undefined
at EventEmitter. (renderer.js:111)
at EventEmitter.emit (events.js:199)

This is my actions variable:

const actions = {  
  getCategories: async (req, res) => {
    var data = openJSON(CONFIG_DIR + path.sep + CAT_FILE);
    if (data === undefined)
      res.send({ categories: [] });
    else
      res.send({ categories: data });
  }
}

I'm calling a function to setup the actions using:

module.exports = {
  setupAPI: function(electron) {
    setupMainHandler(electron, {...actions});
  }
}

And finally in jsx:

emit('getCategories').then((res) => { this.setState({ categories: res.categories });  });

Export preload function

Since 2020 the security of the electron apps require recommend a preload function. To use this lib with preload it could export the preload function.
I am able to make the pull request, it is just a questions if I should?

Export somehow this function

contextBridge.exposeInMainWorld('api', {
  send: (channel: string, requestId: string, action: string, payload: any): void => {
    const validChannel = ['asyncRequest'];
    if (validChannel.includes(channel)) {
      ipcRenderer.send(channel, requestId, action, payload);
    }
  },
  on: (channel: string, callback: Function): void => {
    const validChannel = [
      'asyncResponseNotify',
      'asyncResponse',
      'errorResponse',
    ]
    if (validChannel.includes(channel)) {
      // Strip event but pass an empty object to the callback
      ipcRenderer.on(channel, (_event, ...args) => callback({}, ...args));
    }
  }  
});

So the user can do:

// preload.ts
import electron from 'electron';
import { generatePreload } from 'eiphop';

generatePreload(electron);

res.notify is not a function

I am getting the error [ERROR] TypeError: res.notify is not a function when trying to invoke notify.

When I dump the contents of res all I get is { send: [Function: send], error: [Function: error] }

node: v11.10.1
eiphop: ^1.0.12

emit('ping', {id: 123}, (msg) => {
            console.log(msg)
        })
            .then((res) => console.log(res)) // will log {msg: 'pong'}
            .catch((err) => console.log(err))

const actions = {
    ping: (req, res) => {
        const {payload} = req
        res.notify('Downloading file ${payload.id}')
        res.send({msg: 'pong'})
    },
}

Async action: What happens in case of exception ?

This module looks greate, but i have a question. In the case where the action is async, for exemple:

const actions = {
    test: async (req, res) => {
        const list = await manager.someAsyncFunc();
        res.send(list)
    }
};

Would any error coming from someAsyncFunc be automatically send to renderer ?

Because it looks like right now we are supposed to always try/catch and use res.error.

Proposition

There could be a default errorhandler in the engine that check sends the error automatically. Here what it imagine:

 requestedAction({payload}, {
      send: (res) => event.sender.send('asyncResponse', requestId, res),
      error: (err) => event.sender.send('errorResponse', requestId, err)
    });

could become

const res = {
    send: (res) => event.sender.send('asyncResponse', requestId, res),
    error: (err) => event.sender.send('errorResponse', requestId, err)
};

try {
    const promise = requestedAction({payload}, res);
    ///isPromise needs to be implemented
    if (isPromise(promise)) {
        promise.catch((e) => {
        //error in async code
            res.error(e)
        })
    }
} catch (e) {
    //error inside sync code
    res.error(e);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.