npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

falcor-react

v1.0.1

Published

Falcor integration for React

Downloads

5

Readme

Falcor React Build Status Coverage Status bitHound Score

Falcor integration for React.

Installation

npm install falcor-react

Usage

Initializing the Falcor model

In order to use Falcor in your components, you must decorate the root component of your application (or anyway one that contains all those where you want to use Falcor) with the Root decorator.

import FalcorReact from "falcor-react";
...
@FalcorReact.Root(model)
class Foo extends React.Component {
	...
}

The Root decorator takes exactly one argument, an object, that will be passed as is to the Falcor.Model constructor as a configuration object.

Initializing a component

Each component where you intend to use Falcor must be decorated with the Leaf decorator.

import FalcorReact from "falcor-react";
...
@FalcorReact.Leaf(query)
export default class Foo extends React.Component {
	...
}

The Leaf decorator takes two arguments, both optional.

The first is an initialization query and it must be either a string...

@FalcorReact.Leaf("foo { bar }")

... or an array...

@FalcorReact.Leaf(["foo", "bar"])

... or a function taking the component's props as a parameter and returning either a string or an array.

@FalcorReact.Leaf((props) => {
	return `foo(id: ${props.id}) { bar { foo } }`;
})

You can also initialize a component without a query...

@FalcorReact.Leaf()

... and nest queries (e.g. if you need to retrieve data in multiple steps).

@FalcorReact.Leaf("foo { bar }")
@FalcorReact.Leaf((props) => {
	return `bar(id: ${props.data.foo.bar}) { foo }`;
})

The data retrieved through Falcor will then be available to the decorated component as this.props.data.

The regular Falcor methods will also be available as this.props.call, this.props.get and this.props.set.

An additional method, this.props.reinitialize will also be available and force the initialization query to be run again when invoked.

The second argument of the Leaf decorator is an optional configuration object that slightly changes the behavior of the decorator.

It currently supports two options:

  • defineEmpty (boolean, defaults to false): when set to true, an empty tree with the same shape as the one returned by Falcor with the given initialization query will always be available to the wrapped component, regardless of the result of the query. Its leaves will have null value when no data is available.

  • propsSafety (number, defaults to 1): changes the properties passed to the decorated component as follows, thus either providing shorthands or avoiding conflicts:

    • 0 (or less): call, falcor, get, reinitialize, set, plus one per root element of your query, e.g. the query foo { bar } will add foo to the list.

    • 1: call, data (containing root elements), falcor, get, reinitialize, set.

    • 2 (or more): falcor (containing all the properties above).

Supported Query Syntaxes

The following syntaxes are supported out of the box as query languages and allow for either one or multiple paths to be requested.

"foo { bar(id: 1) { foo } }"
"foo { bar(id: 1) { foo } }, bar(index: 0) { foo }"
"foo.bar[1].foo"
["foo.bar[1].foo", "bar[0].foo"]
  • Array
["foo", "bar", 1, "foo"]
[["foo", "bar", 1, "foo"], ["bar", 0, "foo"]]