it is websocket-store for using easily websocket

Overview

Socket-Store

It is Websocket Store

How to use

1. Install

# npm 
npm install socket-store

# yarn

yarn add socket-store

2. Create MessageHandler and SocketStore

2-1. Create MessageHandler


First, create a message handler.
Define the topic, callback for the topic, and default status. This will be provided in the store.

  • createMessageHandler(key, callback, state)
    • key : it will be subject of message.
    • callback: it will works like reducer. it must return state!
    • state: it is defualt state.
const talkHandler = createMessageHandler<string[], string>(
  "talk",
  (state, data) => {
    return [...state, data];
  },
  []
);

2-2. Create SocketStore

Next, create a socket store. Store gets two parameters for web sockets and message handlers.

//handlers = you can uses like this.
const talkHandler = createMessageHandler('talk', (state, data)=>[...state, data], []);
const tradingHandler = createMessageHandler('trade', (state,data)=>data, null);

const socket = new WebSocket("ws://localhost:3030");
const store = new SocketStore(socket, [talkHandler, tradingHandler]);

2-3. How to send and How to get state

// key is messagehandlers key, data: any type
store.send({key: 'talk', data: {user:'nerd', message:'hello'});

// give to key of messageHandler, then receive state about key.
store.getState('talk'); 
// return state of 'talk' topic
// ex) [{user:'nerd',message:'hi'}, {user:'chanii',message:'Can you help me? '}, {user: 'nerd', message:'kk'}] 

LICENSE

MIT

You might also like...

Awesome-book is an online library website where a user can store a collection of books. Different book can be added and removed. Built with JavaScript using Dom

Awesome-book Description Awesome-book is an online library website where a user can store a collection of books. Differents book can be added and remo

Sep 9, 2022

A store locator plugin using Google Maps API version 3

jQuery Google Maps Store Locator Plugin The files you're looking for are in the dist/ directory Please see my blog for more information and examples.

Dec 12, 2022

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

OCPP-RPC A client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols (e.g. OCPP1.6J and OCPP2.0.1J). Re

Dec 30, 2022

Performant WebSocket Server & Client

Socketich 📨 Performant WebSocket server and persistent client powered by uWebSockets.js and PersistentWebSocket Install npm i @geut/socketich Usage S

Aug 15, 2022

This application provides the CDK project and a frontend that allows you to build a serverless chat application based on API Gateway's WebSocket-based API feature.

This application provides the CDK project and a frontend that allows you to build a serverless chat application based on API Gateway's WebSocket-based API feature.

Serverless chat application using ApiGateway Websockets This project lets you provision a ready-to-use fully serverless real-time chat application usi

Jan 3, 2023

Socket IO Connector for Yjs (Inspired by y-websocket)

Welcome to y-socket.io 👋 Socket IO Connector for Yjs (Inspired by y-websocket) Y-socket.io is a YJS document synchronization implementation over the

Dec 21, 2022

This is a full-stack exercise tracker web application built using the MERN (MongoDB, ExpressJS, ReactJS, NodeJS) stack. You can easily track your exercises with this Full-Stack Web Application.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Dec 25, 2021

Allows the public to easily report and track the geolocation of anyone or anything they spot outside, using a mobile app or web frontend.

Allows the public to easily report and track the geolocation of anyone or anything they spot outside, using a mobile app or web frontend.

LIVE DEMO: https://armytracker.com/ (tracking the invading Russian army in Ukraine) Attention: - If you'd like to help the project either as a program

Mar 27, 2022

Easily create key board shortcuts for your JS functions. Built using JS only with no other dependency. Inspired from MacOS spotlight

floodlightjs Inspired from macOS spotlight, floodlight is simple JS library that will show a search area. How the search is handled is completely on y

Aug 12, 2022
Owner
nerdchanii
nerdchanii
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
An Electron app using NAPI-RS and a native Rust module to implement a Svelte store.

Svelte Store Written in Rust This repo shows a demo of an Electron app running a Svelte UI that reads and writes a Svelte store, but with a twist: the

Dave Ceddia 27 Sep 20, 2022
Awesome book website, small online library to store books when added to the list we have implemented this using a plaint JavaScript!

microverse-m2-Awesome-books This project is about building Awsome Books using javascript Live demo Live Demo Link Built With -Lighthouse (An open-sour

Oybek Kayumov 16 Dec 27, 2022
Minimal E-Commerce Store built with NextJS using Shopify Storefront API

NextJS Shopify Store Minimal E-Commerce Store built with NextJS using Shopify Storefront API Usage: run: npm install && npm run dev OR If you have doc

Omar Magoury 3 Nov 29, 2022
This app was build to store your activities through the day, using HTML, CSS and JavaScript all working with Webpack.

to-do-list In this project i create a To Do List using webpack. This project allows user to add, remove and mark as complete tasks. Built With HTML CS

null 5 May 9, 2022
Store data using zero width spaces! Might be useful for discord bots.

ZWSP Store data using zero width spaces! Might be useful for discord bots. Installation npm i zwsp Usage Import the library: import { encode, decode}

Xaro 8 Dec 12, 2022
Game Store using RAWG API.

Shopping Cart Shopping Cart for The Odin Project Demo ?? Live Demo Built with React TypeScript Framer Motion React Router Sass Features Extensive cata

null 22 Dec 26, 2022
A minimal e-commerce store using Gatsby, SANITY, Stripe, Use-Shopping-Cart and Netlify

?? Gatsby Starter Stripemart Like a supermarket but for Stripe. No ongoing monthly costs. Perfect for artists, creators and independent builders doing

Eric Howey 26 Nov 14, 2022