Socket
Socket
Sign inDemoInstall

recks

Package Overview
Dependencies
2
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    recks

Stream driven framework


Version published
Weekly downloads
18
increased by800%
Maintainers
1
Install size
276 kB
Created
Weekly downloads
 

Readme

Source

Intro to RecksJS

NPM Bundlephobia MIT license

Official docs: recks.gitbook.io

RecksJS is a framework based on streams

import Recks from 'recks';
import { timer } from 'rxjs';

function App() {
  const ticks$ = timer(0, 1000);

  return <div>
    <h1>{ ticks$ }</h1>
    <p>seconds passed</p>
  </div>
}

Try it in this online sandbox or install locally

⚠️ RecksJS is currently in beta

🔎 Overview

Observables are first class citizens in Recks ❤️

function App() {
  return <div>{ timer(0, 1000) }</div>
}

You can also do other way around: map a stream on JSX

function App() {
  return timer(0, 1000).pipe(
    map(x => <div>{ x }</div>)
  );
}

Recks will subscribe to and unsubscribe from provided streams automatically, you don't have to worry about that!

And you can use Promises that will display the result, once resolved:

function App() {
  const result = axios.get(url).then(r => r.data);

  return <div>
    { result }
  </div>
}

To get a better understanding of Recks concepts, read this article: "Intro to Recks: Rx+JSX experiment" and check out API docs section

📖 Examples

1. Hello world

Just a basic, no "moving parts"

import Recks from 'recks';

function App() {
  return <h1>Hello world!</h1>
}

2. Timer

RxJS' timer here will emit an integer every second, updating the view

import Recks from 'recks';
import { timer } from 'rxjs';

function App() {
  const ticks$ = timer(0, 1000);

  return <div>
    <h1>{ ticks$ }</h1>
    <p>seconds passed</p>
  </div>
}

online sandbox

3. Greeting

Uses a simple Subject to store local component state:

import Recks from 'recks';
import { Subject } from 'rxjs';
import { map, startWith } from 'rxjs/operators';

function App() {
  const name$ = new Subject();
  const view$ = name$.pipe(
    map(x => x ? `Hello, ${x}!` : ''),
    startWith('')
  );

  return <div>
    <input
      placeholder="enter your name"
      onInput={e => name$.next(e.target.value)}
    />
    { view$ }
  </div>
}

online sandbox

4. Counter

Traditional counter example with a Subject:

import Recks from 'recks';
import { Subject } from 'rxjs';
import { scan, startWith } from 'rxjs/operators';

function App() {
  const input$ = new Subject();
  const view$  = input$.pipe(
      startWith(0),
      scan((acc, curr) => acc + curr)
    );

  return <div>
    <button onClick={ ()=>input$.next(-1) }>
      minus
    </button>

    { view$ }

    <button onClick={ ()=>input$.next( 1) }>
      plus
    </button>
  </div>
}

online sandbox

📚 Docs

Continue reading:

Keywords

FAQs

Last updated on 21 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc