Coder Social home page Coder Social logo

reactiveelements's Introduction

Reactive Elements

Convert React.js components into Web Components

Compatible with any custom elements implementation or polyfill.

Demo

UPD Convert Angular and Backbone views as well with MVC elements project

Example

Using component in HTML

<body>
	<my-react-component items="{window.someArray}"></my-react-component>
</body>

React component definition

/* @jsx React.DOM */
MyComponent = React.createClass({
  render: function() {
    console.log(this.props.items);
    console.log(this.props._content); // original tag contents in a <content>
    return <ul><li>React content</li></ul>;
  }
});

document.registerReact('my-react-component', MyComponent);

Find demo in corresponding folder.

Nesting

Original content of a custom element is injected to component as this.props._content.

<my-react-component>Hello world</my-react-component>

In this case props._content is equal to "Hello world".

Handling attributes change

You may add attributeChanged callback to component in order to handle / modify / filter incoming values.

attributeChanged: function(attributeName, oldValue, newValue) {
    console.log('Attribute ' + attributeName + ' was changed from ' + oldValue + ' to ' + newValue);
    this.props[attributeName] = parseInt(newValue);
}

Communicate via DOM events

You may trigger DOM event from React component by using following snippet:

var event = new CustomEvent('change', {
      bubbles: true
    });
this.getDOMNode().dispatchEvent(event)

Subscribing to DOM events is similar:

this.getDOMNode().addEventListener('change', function(e){...});

NPM and Bower

  • NPM: reactive-elements
  • Bower: ReactiveElements

Dependencies

  • React.js
  • function.bind and Object.create support or polyfills
  • Custom elements support or polyfill

Custom elements polyfill behavior

Polyfill binds to DOMContentLoaded in order to process DOM so no custom elements exist until it fired. To prevent this hook into DOMContentLoaded and operate elements on it or after.

License

MIT: http://mit-license.org/

Copyright 2014 Denis Radin aka PixelsCommander

Inspired by Christopher Chedeau`s react-xtags

reactiveelements's People

Contributors

pixelscommander avatar addyosmani avatar jakobo avatar codejet avatar gusnips avatar gitter-badger avatar rektide avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.