by Leonardo Garcia Crespo
github/leoasis
var strength = getPasswordStrength(text);
if (text.length == 0) {
removeInputBorder();
if (hasMessage()) {
removeMessage();
}
if (hasSmiley()) {
removeSmiley();
}
} else if (strength == 'weak') {
setInputBorder('red')
var message = 'Weak';
if (hasMessage()) {
setMessageText(message);
} else {
addMessageWithText(message);
}
if (hasSmiley()) {
removeSmiley();
}
} else {
setInputBorder('green')
var message = "That's what I call a password!";
if (hasMessage()) {
setMessageText(message);
} else {
addMessageWithText(message);
}
if (!hasSmiley()) {
addSmiley();
}
}
T = Number of Transitions
S = Number of States
var strength = getPasswordStrength(text);
if (text.length == 0) {
return div(input({type: 'password', value: text}));
} else if (strength == 'weak') {
return div(
input({type: 'password', value: text, borderColor: 'red'}),
span({}, "Weak")
);
} else {
return div(
input({type: 'password', value: text, borderColor: 'green'}),
span({}, "That's what I call a password!"),
i({class: 'icon-smiley'})
);
}
Future's made of
/** @jsx React.DOM */
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() {
return (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
});
React.renderComponent(<Timer />, mountNode);
Just Javascript!
var Timer = React.createClass({displayName: 'Timer',
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() {
return (
React.DOM.div(null, "Seconds Elapsed: ", this.state.secondsElapsed)
);
}
});
React.renderComponent(Timer(null), mountNode);
github/leoasis
@leogcrespo