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

react-marionette

v0.6.1

Published

Connects your [Marionette](https://marionettejs.com/) views and [React](https://reactjs.org/) components.

Downloads

155

Readme

react-marionette npm Travis Coveralls

Connects your Marionette views and React components.

The library provides a bidirectional gateway between the two technologies:

  1. ReactView and ReactBehavior - renders React components inside your Marionette views.
  2. MarionetteComponent - renders Marionette views inside your React components.

Installation

The react-marionette library is provided as an NPM package:

$ npm install --save react-marionette

ReactView

const view = new ReactView({
    className: 'react-wrapper',
    render: () => <div className="react-component">Hello, React</div>
});
someRegion.show(view);

/*
Result:
<div class="react-wrapper">
    <div class="react-component">
        Hello, React
    </div>
</div>
*/

The simplest way to render React components in your Marionette layout. Inside, creates a new mount point using ReactDOM.render and unmounts on view destroy.

render - a function that returns a React node.

mountPoint - 'onRender' or 'onShow', defines the point at which the render of the React node occurs. Default: 'onShow'.

A more complicated example using Redux for state management and rendering a connected component:

const view = new ReactView({
    className: 'react-wrapper',
    render: () => {
        return (
            <Provider store={store}>
                <SomeConnectedComponent />
            </Provider>
        );
    }
});
someRegion.show(view);

ReactBehavior

const View = Marionette.ItemView.extend({
    template: false,
    className: 'marionette-root',
    behaviors() {
        return {
            ReactBehavior: {
                behaviorClass: ReactBehavior,
                containerEl: null,
                render: () => <div className="react-component">Hello, React!</div>,
                mountPoint: 'onRender'
            }
        };
    }
});

/*
Result:
<div class="react-wrapper">
    <div class="react-component">
        Hello, React
    </div>
</div>
*/

This behavior gives you more flexibility when rendering a React node by providing the containerEl option. Apart from this, the underlying render logic is the same as in ReactView.

render - a function that returns a React node.

mountPoint - 'onRender' or 'onShow', defines the point at which the render of the React node occurs. Default: 'onShow'.

containerEl - a jQuery selector that identifies the element that should be used to render the react node. Similarly to the ui selectors in Marionette.View, this selector is scoped to the view which this behavior is applied to.

MarionetteComponent

const SimpleView = Marionette.ItemView.extend({
    template({ name }) {
        return `Hello, ${name}`;
    },
    templateHelpers() {
        return {
            name: this.options.name
        };
    },
    className: 'simple-view'
});
export const SomeStatelessComponent = () => {
    return (
        <div className="react-block">
            <MarionetteComponent
                className="marionette-wrapper"
                view={SimpleView}
                viewOptions={{
                    name: 'Marionette'
                }}
            />
        </div>);
};

/*
Result:
<div class="react-block">
    <div class="marionette-wrapper">
        <div class="simple-view">
            Hello, Marionette
        </div>
    </div>
</div>
*/

A reverse gateway allowing to render a Marionette view inside your React code. Once rendered, the marionette view is not updated on viewOptions change unless it is defined in onUpdateOptions.

view - a Marionette.View class to be rendered.

viewOptions - options to be passed to the view when it is constructed.

className - a class that can be optionally set to the wrapper div element of MarionetteComponent.

onUpdateOptions(view, viewOptions, nextViewOptions) - a callback which is called when the view options change. Allows to manually update the view on options change:

onUpdateOptions(view, viewOptions, nextViewOptions) {
    if (viewOptions.name !== nextViewOptions.name) {
        view.options = nextViewOptions;
        view.render();
    }
}

Alternatively, shouldViewRebuild can be implemented inside the View to handle it's update requests:

const SimpleView = Marionette.ItemView.extend({
    template({ name }) {
        return `Hello, ${name}`;
    },
    templateHelpers() {
        return {
            name: this.options.name
        };
    },
    className: 'sample-view',
    shouldViewRebuild(nextOptions) {
        // Or just implement the update logic here and return false
        return true;
    }
});