Code Monkey home page Code Monkey logo

callbag-doki's Introduction

callbag-doki

callbag-doki is a new lib for reactive programing inspired by RxJS and based on callbag specs.
If you already use functions based on callbag specs, you can import only some sources or operators and use them with other packages based on the same spec.

Motivation

I was looking for a lightweight alternative of RxJS because it was 1 of my biggest dependency for a mobile web-app. Then I discover callbag A standard for JS callbacks that enables lightweight observables and iterables. Even if there are already some sources and operators available, I was interessed by creating my own lib to have a better knowledge about how a reactive library works under the hood.

Installation

yarn add @epimodev/callbag-doki

# or with npm

npm install --save @epimodev/callbag-doki

Examples

Basic source with subscription:

import subscribe from '@epimodev/callbag-doki/utils/subscribe'
import interval from '@epimodev/callbag-doki/sources/interval'

const unsubscribe = subscribe(interval(1000))(count => console.log(count))
// 1
// 2
// 3

setTimeout(() => {
  unsubscribe()
}, 3500)

Source transformed with operator:

import subscribe from '@epimodev/callbag-doki/utils/subscribe'
import pipeSource from '@epimodev/callbag-doki/utils/pipeSource'
import interval from '@epimodev/callbag-doki/sources/interval'
import map from '@epimodev/callbag-doki/operators/map'

const customInterval = pipeSource(
  interval(1000),
  map(count => count * 2),
)

const unsubscribe = subscribe(customInterval)(value => console.log(value))
// 2
// 4
// 6

setTimeout(() => {
  unsubscribe()
}, 3500)

http request:

import subscribe from '@epimodev/callbag-doki/utils/subscribe'
import httpRequest from '@epimodev/callbag-doki/sources/httpRequest'

const httpSource = httpRequest({ url: 'https://jsonplaceholder.typicode.com/albums' })

const cancelRequest = subscribe(httpSource)({
  next: response => console.log('Succeed: ', response),
  error: err => console.log('Failed: ', err),
  complete: () => console.log('Complete'),
})

List of sources

List of operators

callbag-doki's People

Contributors

epimodev 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.