Coder Social home page Coder Social logo

busin-riccardo / recks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from recksjs/recks

0.0 1.0 0.0 558 KB

๐Ÿถ React-like RxJS-based framework

Home Page: https://recks.gitbook.io/

License: MIT License

JavaScript 1.94% TypeScript 98.06%

recks's Introduction

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:

recks's People

Contributors

kosich avatar demensky avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.