Open PabloReszczynski opened 6 years ago
Example:
// Simple Usage
import dva from 'dva';
import createSocket from 'dva-socket.io';
import io from 'socket.io-client';
const app = dva();
app.use(createSocket('http://127.0.0.1:8080', null, io, {
// when server push an server-message event,
// it will dispatch an action use server data,
on: ['server-message'],
emit: [
// when you dispatch an action with type === 'send-message',
// it will emit a client-message event with data('client send a message')
[
'client-message',
(action) => action.type === 'send-message',
'client send a message',
],
],
}));
https://github.com/elvin-gogo/dva-socket.io
createDvaSocket(url, options, rules, ref_io); // ref_io is target socket.io
@PabloReszczynski Awesome idea. I have saw that maybe no everybody want the same version of socket.io-client. So the next version will add custom io
. If you have done that, give a pr, thanks.
And another question: mocks for testing
, can you give me an example, which show what you want ?
@Elvin1993 Awesome. It looks good.
mock for testing is use this one mock-socket
With a mock socket, I could use all the features of dva-socket.io without having to use a real socket connection, very useful for testing. mock-socket is a well known library that does it.
Thanks. I know.
About custom socket.io version or mock-socket, @elvin-gogo @Elvin1993 have committed a good pr #5 . I have released a new version 0.0.6. Maybe you can try it. I will renew the docs latter.
This would allow to use any version of socket.io with this plugin and also allow the use of socket.io mocks for testing.