Socket
Socket
Sign inDemoInstall

tiny-frp

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-frp

A tiny state management library built for ProgrammersWeek 2021


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

TinyFRP (TFRP)

A tiny transparent function reactive library built for didactic purposes.

Originally meant to illustrate the points about transparent reactive programming during ProgrammersWeek 2021 event, so it's definitely not production ready.

API

The library exports 3 functions: observable, effect and computed , the building blocks of any reactive library. It does not offer wrappers around various used land frameworks since their implementation it's pretty simple and can be easily achieved using used land code.

observable(data)

Wraps any data, either primitive or objects and turns it into an observable entity.

Wrapping a primitive returns an object with a single property: value.

effect(fn)

Executes a function a tracks the observables used inside it. It re-runs the fn function whenever any read observable property changes.

        const o = observable({firstName: 'a', lastName: 'b'});
        const effectFn = () => { console.log(`${o.firstName}-${o.lastName}`); };
        const unsubscribe = effect(effectFn);
        unsubscribe();

Returns a function that, when called, it removes the watches on any tracked observable properties.

computed(fn)

A variation of the effect function that is meant to compute derived values. Just as effect it auto-magically tracks any read observables inside the fn function but it also memoizes the return value of fn() until any tracked observables change.

As such fn is deemed to be a PURE function and return a value.

        const o = observable({firstName: 'a', lastName: 'b'});
        const computedFn = () => `${o.firstName}-${o.lastName}`;
        const fullName = computed(computedFn);
        console.log(fullName.value);

It returns an observable instance wrapping whatever value fn() returned.

FAQs

Package last updated on 13 Sep 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc