euaaaio / logux-redux

Redux compatible API for Logux

Home Page:https://logux.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logux Redux

Logux is a new way to connect client and server. Instead of sending HTTP requests (e.g., AJAX and GraphQL) it synchronizes log of operations between client, server, and other clients.

This repository contains Redux compatible API on top of Logux Client.

Sponsored by Evil Martians

Install

npm install @logux/redux redux

Usage

See documentation for Logux API.

import { createLoguxCreator } from '@logux/redux'
import { log } from '@logux/client'

let userId = document.querySelector('meta[name=user]').content
let token = document.querySelector('meta[name=token]').content

const createStore = createLoguxCreator({
  subprotocol: '1.0.0',
  server: 'wss://example.com:1337',
  userId,
  token
})

const store = createStore(reducers, preloadedState)
log(store.client)

export default store
import { Provider } from 'react-redux'
import ReactDOM from 'react-dom'

import store from './store'
import App from './App'

ReactDOM.render(
  <Provider store={store}><App /></Provider>,
  document.getElementById('root')
)
import { useSubscription } from '@logux/redux'

export const User = ({ id, name }) => {
  const isSubscribing = useSubscription([`user/${ id }`])
  if (isSubscribing) {
    return <Loader />
  } else {
    return <h1>{ name }</h1>
  }
}

About

Redux compatible API for Logux

https://logux.io/

License:MIT License


Languages

Language:TypeScript 77.2%Language:JavaScript 22.8%