Front-end Hyperpolyglot
Inspired by hyperpolyglot.org, a comparison of similar features in popular JavaScript frameworks.
Any contributors who are more familiar with these frameworks would be massively appreciated. The source is on GitHub.
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
---|---|---|---|---|---|---|---|
Version used | |||||||
Language used | |||||||
Templating logic | |||||||
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
Text interpolation | |||||||
Transform interpolation | |||||||
Transform with arguments | |||||||
Bind text content | |||||||
Bind href | |||||||
Dangerous raw HTML output | see notes | ||||||
Bind attribute value | |||||||
DOM add/remove | |||||||
Repeat | |||||||
Bind event handler | |||||||
Components | |||||||
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
Define component ES6 | |||||||
Define component ES5 | |||||||
Component communication | |||||||
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
One-way data binding | |||||||
String literal prop | |||||||
Two-way binding (native) | not supported | not supported | |||||
Two-way binding (components) | not supported | not supported | |||||
One-time binding | not supported | not supported | not supported | not supported | not supported | ||
Component internal state | |||||||
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
Set initial state | |||||||
Set state | |||||||
Property validation | |||||||
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
Prop validation key | as types on @Input properties (below) | (no prop types) | (no prop types) | ||||
Prop validate Number | (no prop types) | (no prop types) | |||||
Prop validate String | (no prop types) | (no prop types) | |||||
Prop validate Array | (no prop types) | (no prop types) | |||||
Prop validate Boolean | (no prop types) | (no prop types) | |||||
Prop validate Function | (no prop types) | not supported | not supported | (no prop types) | |||
Prop validate Object | (no prop types) | (no prop types) | |||||
Prop validate union | (no prop types) | not supported | (no prop types) | ||||
Component lifecycle methods | |||||||
React | Angular 2 | Angular 1 | Ember | Polymer | Vue | Riot | |
Initialized | |||||||
DOM Ready | |||||||
On prop change | none | ||||||
Component updated | none | none | none | none | |||
Before destroy | none | none | |||||
After destroy | none | none | none |
Templating logic
Text interpolation
- Polymer: see Binding to text content.
Transform interpolation
React, Riot and Polymer don’t have the concept of ‘filters’ or ‘pipes’, but you can use a simple function to acheive the same result.
Transform with arguments
Bind text content
A way of binding the text content of an element via an attribute.
- Angular 1: See
ngBind
. - Polymer: See Annotated attribute binding
Bind href
- Angular 2: See bind to the
href
property. - Angular 1: See
ngHref
. - Polymer: See Binding to native element attributes.
- Vue: See Directives > Arguments.
Dangerous raw HTML output
Please don’t use these in your programs. Filtering raw HTML on the server or in the browser will not protect you 100% against XSS. For a deeper look at the subject, please refer to the Google Browser Security Handbook (PDF download) and the book The Tangled Web: A Guide to Securing Modern Web Applications.
- React: See Dangerously Set innerHTML.
- Vue: See Raw HTML.
- Riot: Riot doesn’t directly support this, though you can set
innerHTML
usingthis.root.querySelector
Bind attribute value
- Angular 2: See Attribute, class, and style bindings
- Vue: See Attributes
DOM add/remove
- Angular 2: See Angular Cheat Sheet.
Repeat
- Angular 1: See
ngRepeat
. - Polymer: See Template repeater (
dom-repeat
).
Bind event handler
- Polymer: See Annotated event listener setup.
Components
Define component ES6
- Polymer: See Building web components using ES6 classes
- Vue: See gist: Vue.js + ES6
Define component ES5
- Polymer: See Building web components using ES6 classes
- Vue: See gist: Vue.js + ES6
Component communication
One-way data binding
- Polymer: The child component must also be set up to treat the property as read-only. Learn more about data binding in Polymer.
Two-way binding (native)
- Polymer: See Two-way binding to native elements.
Two-way binding (components)
- Polymer: See Property change notification and two-way binding.
One-time binding
When a property is passed down and never updated again.
- Angular 1: See One-time binding.
- Polymer: See Creating a One Time Binding in polymer-patterns.
Component internal state
Property validation
Prop validation key
The key in the component configuration object to define the expected type of a passed prop.
class Polyglot extends React.Component {
propTypes = {
myNumber: React.propTypes.number
}
}
- React: Learn more about
propTypes
in React. - Angular 2: Learn more about Basic Types in TypeScript.
- Polymer: Learn more about declared properties in Polymer.
- Vue: Learn more about prop validation in Vue.
- Ember: Learn more about prop validation in Ember.
Prop validate union
- Angular 2: Advanced Types in TypeScript
Component lifecycle methods
Initialized
- React:
componentWillMount
- Angular 1: See https://docs.angularjs.org/guide/component#component-based-application-architecture.
DOM Ready
- React:
componentDidMount
On prop change
- React:
willReceiveProps
Component updated
- React:
componentDidUpdate
Before destroy
- React:
componentWillUnmount
After destroy
- React has no
componentDidUnmount
method. See ReactClass.js#L274.