const Link = (props) => (
<a href={props.href}>
{props.children}
</a>
)
const App = (props) => (
<Link href="/profile">
<img src="/avatar.png" onClick={window.reload} />
</Link>
)
ReactDOM.renderToStaticMarkup(<App />)
// => "<a href="/profile"><img src="/avatar.png" /></a>"
ReactDOM.render(<App />, document.body)
// => Also attaches onClick handlerconst Link = (props) => ({
type: "a",
props: {
href: props.href,
children: props.children
}
})
const App = (props) => ({
type: Link,
props: {
url: "/profile",
children: [{
type: "img",
params: {
src: "/avatar.png",
onClick: window.reload
}
}]
}
})
ReactDOM.render({ type: App }, document.body)const Link = (props) => (
<a href={props.url}>
{props.children}
</a>
)
const App = (props) => (
<Link url="/profile">
<img
src="/avatar.png"
onClick={window.reload}
/>
</Link>
)
ReactDOM.render(<App />, document.body)// state.js
import Immstruct from 'immstruct'
export default Immstruct({
user: {
id: 1,
avatar: "/avatar.png"
},
visiblePosts: [
{
title: 'Hello world',
body: 'Lorem ipsum dolor is amet'
}
]
})action is a plain object
that describes what happened
state = update(state, { type: 'LIKE_ARTICLE', articleId: 42 })
state = update(state, { type: 'ADD_TODO', text: 'Read about Flux.'})// userService.js
import dispatcher from './dispatcher'
import state from './state'
dispatcher.register(function(payload) {
if (payload.type === 'UPDATE_USER_AVATAR') {
state.update(['user', 'avatar'], payload.url)
}
});angular.module('app')
.directive('editUser', function() {
return {
restrict: 'E',
transclude: true,
controller: function ($scope, dispatch) {
$scope.onClickSave = function() {
dispatch({ type: 'CHANGE_USER_AVATAR', url: $scope.url })
}
}
};
});const state = {
user: {
id: 1,
avatar: "/avatar.png"
}
}
const App = (state) => (
<Link href={`/profile/${state.user.id}`}>
<img src={state.avatar} />
</Link>
)
ReactDOM.render(App, state)repeat
repeat
angular.module('app')
.directive('application', function () {
return {
restrict: 'E',
replace: true,
template: require('./application.html')
};
});<div class="application">
${require('./header.html')}
<div class="content">
<ng-transclude></ng-transclude>
</div>
${require('./footer.html')}
</div><img src="${require('../assets/logo.png')}" />
// In production becomes:
<img src="/assets/logo-b524a2537.png" />
// Can also compile for data uri for small assets!
<img src="data:image/png;base64,iVBORw0KGgoAAAA..." />${this.styles = require('./index.css'), ""}
<div class="${this.styles.logo}">
Hello world
</div>/* index.css */
.logo {
color: red;
}<div class="_3gBJbu7o592GGUQ4CjIQTM">
Hello world
</div>._3gBJbu7o592GGUQ4CjIQTM {
color: red;
}- Don't use ng-controller
- Make everything a directive
- Always use isolated scope (explicitly pass properties)
- Don't use $rootScope and other globals
- Use double-binding only locally (if you need)
- Use only factories (forget about services, providers, factories, constants, they return singletons anyway)
I'm searing for good:
- Ruby & Rails developers
- JavaScript developers (React)
European Salary