JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
// The Provider component will be our root component
// It connects our app to the store
const {Provider} = ReactRedux;
// The App component is the root of our app itself.
var App = (props) =>
<div>
<h1>Tomb of the Ancients</h1>
<HeroContainer></HeroContainer>
</div>
// Hero is a presentational (dumb) component
// that recieves a hero as a prop and renders it
var Hero = (props) =>
<div className="hero">
<h2>{props.hero.name}</h2>
<pre>
{JSON.stringify(props, null, 2)}
</pre>
<button onClick={
() => store.dispatch({
type:"DAMAGE_HERO",
value: 1
})
}>
Damage
</button>
<button onClick={
() => store.dispatch({
type:"HEAL_HERO",
value: 10
})
}>
Heal
</button>
</div>
// A container (smart) component, that gets heros
// from the store, and passs them as props to the
// Heros component
var HeroContainer = ReactRedux.connect(
(state) => ({hero: state.hero})
)(Hero);
// The initial state for the app
const initialState = {
hero: {
name: "Haldane Goodguy",
type: "Swordsman",
maxHp: 36,
hp: 36,
armour: 33,
attack:12
},
monster: {
name: "Vlad the Bad",
type: "Necromancer",
maxHp: 300,
hp: 300,
armour: 28,
attack:2
}
}
/* The Hero Reducer only has to deal with heros */
const heroReducer = (hero=initialState.hero, action) => {
switch (action.type) {
case "DAMAGE_HERO":
return { ...hero, hp:hero.hp - action.value }
case "HEAL_HERO": {
let newHero = {...hero, hp: hero.hp + action.value }
if (hero.hp > hero.maxHp) { hero.hp = hero.maxHp }
return newHero
}
default:
return hero
}
}
/* The Hero Reducer only has to deal with heros */
const monsterReducer = (monster=initialState.monster, action) => {
switch (action.type) {
case "DAMAGE_MONSTER":
return { ...monster, hp:monster.hp - action.value }
case "MONSTER_OVERDRIVE":
return { ...monster, attack:500, armour:1000 }
default:
return monster
}
}
/* We create a new reducer by combining other reducers */
const reducer = Redux.combineReducers({
hero:heroReducer,
monster:monsterReducer
});
const store = Redux.createStore(reducer);
store.subscribe(() =>
console.log(store.getState())
)
// setInterval(() => store.dispatch({type:"SET_NAME", value: "Dave"}), 1000);
// setInterval(() => store.dispatch({type:"SET_NAME", value: "Mike"}), 1300);
ReactDOM.render(
<Provider store={store}>
<App></App>
</Provider>,
document.getElementById('app'))
Also see: Tab Triggers