Skip to content

Kr0na/point-socket.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Point Socket.io - is an extension for point-one that allows you to work with sockets

listenSocketIo - use it with compose on store creation

const finalCreateStore = compose(
  listenSocketIo('ws://localhost:3000', {
    'message': CHAT_MESSAGE,
    'reply': data => {
      if (data.targetUser == myUser) {
        return {
          ...data,
          type: CHAT_REPLY_OWN
        }
      } else {
        return {
          ...data,
          type: CHAT_REPLY
        }
      }
    }
  }),
  devTools('ChatStore')
)

const store = finalCreateStore(chatReducers, {
  chat: []
})

Second parameter is an object with:

  • key - socket.io event
  • value - string of event type that will be used on dispatch ({...dataFromPromise, type: valueOfEventsParameter}) or callback that must return an event

createSocketAction - use it for create Actions that should be sent to socket.io server

export let sendMessage = createSocketAction(data => {
  return {
    ...data,
    type: CHAT_MESSAGE
  }
})

It's also works with promise actions (but only success) and Positive Actions (also only success)

About

Point One extension for Socket.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published