buhrmi / cablestore

Connect Svelte stores with server-side application code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CableStore

CircleCI Gem Version npm version

CableStore gives you Svelte stores that connect to your Rails application via ActionCable and can be manipulated via your server-side application code.

Note It's still early, and there's currently no way to configure the Websocket URL (it uses the Rails default /cable).

Installation

Ruby gem

Add this line to your application's Gemfile:

gem 'cablestore'

And then execute:

$ bundle install

Npm package

Install the package:

$ yarn add @buhrmi/cablestore

Usage

Subscribe to an ActiveRecord object

To subscribe to ActiveRecord object, you have to pass the signed Global ID to the frontend. For example, via a controller action:

def show
  @sgid = User.to_signed_global_id(expires_in: nil).to_s
end

Then you can subscribe to it in your client-side code:

import { subscribe } from '@buhrmi/cablestore'

const store = subscribe(sgid, nil, 'current_user')

About

Connect Svelte stores with server-side application code

License:MIT License


Languages

Language:Ruby 73.3%Language:HTML 15.5%Language:JavaScript 9.1%Language:Svelte 1.1%Language:TypeScript 0.9%Language:CSS 0.1%