Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Baret is a library that allows you to embed Bacon.js observables into React VDOM
Baret is a library that allows you to embed Bacon.js observables into React Virtual DOM. Embedding observables into VDOM has the following benefits:
ref
for
component lifetime, leading to more concise code.Using Baret couldn't be simpler. You just import React from "baret"
and you
are good to go.
To use Baret, you simply import it as React
:
import React from "baret"
and you can then write React components:
const oncePerSecond = Bacon.interval(1000).toProperty()
const Clock = () =>
<div>
The time is {oncePerSecond.map(() => new Date().toString())}.
</div>
with VDOM that can have embedded Bacon.js observables.
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 baret
.
baret-lift
attributeBaret only lifts built-in HTML elements implicitly. The baret-lift
attribute
on a non-primitive element instructs Baret to lift the element.
For example, you could write:
import * as RR from "react-router"
import React from "baret"
const Link1 = ({...props}) => <RR.Link baret-lift {...props}/>
to be able to use Link1
with
embedded Bacon.js observables:
<Link1 href="https://www.youtube.com/watch?v=Rbm6GXllBiw"
ref={elem => elem && elem.focus()}>
{Bacon.sequentially(1000, [3, 2, 1, "Boom!"])}
</Link1>
Note that the ref
attribute is only there as an example to contrast
with $$ref
.
fromBacon(observableVDOM)
fromBacon
allows one to convert a Bacon observable of React elements into a
React element. It is useful in case the top-most element of a component depends
on a Bacon observable.
For example:
import {fromBacon} from "baret"
import {ifte} from "baret.util"
const Chosen = ({choice}) =>
fromBacon(ifte(choice, <True/>, <False/>))
Here ifte
from baret-util
returns an observable that is <True/>
when
choice
is true and otherwise <False/>
.
Note that the point of using fromBacon
in the above example is that we don't
want to wrap the ifte(...)
inside an additional element like this:
const Chosen = ({choice}) =>
<div>
{ifte(choice, <True/>, <False/>)}
</div>
fromClass(Component)
fromClass
allows one to lift a React component.
For example:
import * as RR from "react-router"
import {fromClass} from "baret"
const Link2 = fromClass(RR.Link)
WARNING: A difficulty with lifting components is that you will then need to
use the $$ref
attribute, which is not necessary when
using baret-lift
to lift an element.
$$ref
attributeThe $$ref
attribute on an element whose component is lifted using fromClass
<Link2 href="https://www.youtube.com/watch?v=Rbm6GXllBiw"
$$ref={elem => elem && elem.focus()}>
{Bacon.sequentially(1000, [3, 2, 1, "Boom!"])}
</Link2>
does the same thing as the ordinary
JSX
ref
attribute:
JSX/React treats ref
as a special case and it is not passed to components, so
a special name had to be introduced for it.
FAQs
Baret is a library that allows you to embed Bacon.js observables into React VDOM
The npm package baret receives a total of 4 weekly downloads. As such, baret popularity was classified as not popular.
We found that baret demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.