/cablestore

Connect Svelte stores with server-side application code

Primary LanguageRubyMIT LicenseMIT

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')