New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

karet

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karet

Karet is a library that allows you to embed Kefir properties into React VDOM

  • 3.0.0-2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55
decreased by-64.52%
Maintainers
1
Weekly downloads
 
Created
Source

[ | Tutorial | Reference ]

Karet

Karet is a library that allows you to embed Kefir properties into React Virtual DOM. Embedding observable properties into VDOM has the following benefits:

  • It allows you to use only functional components, because you can then use observables for managing state and component lifetime, leading to more concise code.
  • It helps you to use React in an algorithmically efficient way:
    • The body of a functional component is evaluated only once each time the component is mounted.
    • Only elements that contain embedded properties are rerendered when changes are pushed through observables. An update to a deeply nested VDOM element can be an O(1) operation.

Using Karet couldn't be simpler. You just import * as React from 'karet' and you are good to go.

npm version Gitter Build Status Code Coverage

Contents

Tutorial

To use Karet, you simply import it as React:

import * as React from "karet"

and you can then write React components:

const oncePerSecond = Kefir.interval(1000).toProperty(() => {})

const Clock = () =>
  <div>
    The time is {oncePerSecond.map(() => new Date().toString())}.
  </div>

with VDOM that can have embedded Kefir properties. This works because Karet exports an enhanced version of createElement.

NOTE: Karet does not pass through all named React exports. Only createElement and Fragment are exported, which is all that is needed for basic use of VDOM or the Babel JSX transform.

NOTE: The result, like the Clock above, is just a React component. If you export it, you can use it just like any other React component and even in modules that do not import karet.

Reference

Fragment

In addition to createElement, Karet exports React's Fragment component and lifts fragments implicitly.

karet-lift attribute

Karet only lifts built-in HTML elements and fragments implicitly. The karet-lift attribute on a non-primitive element instructs Karet to lift the element.

For example, you could write:

import * as RR    from "react-router"
import * as React from "karet"

// ...

<RR.Link karet-lift
         href="https://www.youtube.com/watch?v=Rbm6GXllBiw">
  {Kefir.sequentially(1000, [3, 2, 1, "Boom!"]).toProperty()}
</RR.Link>

to be able to use RR.Link with embedded Kefir properties.

fromClass(Component)

fromClass allows one to lift a React component.

For example, you could write:

import * as RR from "react-router"
import {fromClass} from "karet"

const Link = fromClass(RR.Link)

to be able to use Link with embedded Kefir properties:

<Link href="https://www.youtube.com/watch?v=Rbm6GXllBiw">
  {Kefir.sequentially(1000, [3, 2, 1, "Boom!"]).toProperty()}
</Link>

Keywords

FAQs

Package last updated on 16 Apr 2018

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