Skip to content

Instantly share code, notes, and snippets.

View JonathonAshworth's full-sized avatar

Jonathon Ashworth JonathonAshworth

  • Everest Engineering
  • Melbourne, Australia
View GitHub Profile
@JonathonAshworth
JonathonAshworth / inOtherFunction.js
Last active December 10, 2016 01:44
Callbacks in React
const SomeComponent = React.createClass({
propTypes: {
doSomething: React.PropTypes.func
},
someOtherFunction: function() {
// Do some other stuff
this.props.doSomething();
},
@JonathonAshworth
JonathonAshworth / declarative.js
Last active December 13, 2016 01:40
Switch Statements vs Chained Ternaries
const Foo = React.createClass({
propTypes: {
bar: React.propTypes.string
},
render: function() {
return (
<div>
{
const foo = {/* stuff here... */};
const pSomething = new Promise(() => foo.bar.baz.yeah.nah.something);
pSomething.then(something => {
// Same as if
}).catch(() => {
// Same as else
});
@JonathonAshworth
JonathonAshworth / timeOfDaySelector.js
Last active December 13, 2016 04:49
Example of a selector with 30 minute increments from 12:00 AM to 11:30 PM
import React from 'react';
import moment from 'moment';
const Foo = React.createClass({
render: function() {
let times = [], timeIterator = moment(0);
for(let i = 0; i < 48; i++) {
times.push(timeIterator);
timeIterator.add(30, "minutes");
@JonathonAshworth
JonathonAshworth / initAction.lua
Last active January 27, 2017 08:39
Frost Death Knight rotation weakaura
aura_env.updateInterval = 0.05
aura_env.lastUpdate = GetTime()
-- SpellID of the spell icon we're showing
aura_env.recommended = 212812
-- How many milliseconds until we should use the next ability
aura_env.recommendedWait = 0
-- Abilities
@JonathonAshworth
JonathonAshworth / webpack.config.js
Last active February 2, 2017 08:40
Webpack 2 Configuration
const path = require('path');
const webpackSettings = {
entry: `${__dirname}/src/index.js`,
output: {
path: `${__dirname}/static/`,
publicPath: '/',
filename: 'bundle.js'
},
@JonathonAshworth
JonathonAshworth / initAction.lua
Created February 16, 2017 06:05
Boomkin version of the WA
-- init
aura_env.updateInterval = 0.05
aura_env.lastUpdate = GetTime()
-- SpellID of the spell icon we're showing
aura_env.recommended = 212812
-- How many milliseconds until we should use the next ability
aura_env.recommendedWait = 0
@JonathonAshworth
JonathonAshworth / reselect.js
Created February 27, 2017 02:37
Reselect vs Vanilla
import { createSelector } from 'reselect';
const shopItemsSelector = state => state.shop.items;
const taxPercentSelector = state => state.shop.taxPercent;
const subtotalSelector = createSelector(
shopItemsSelector,
items => items.reduce((acc, item) => acc + item.value, 0)
);
const Article = React.createClass({
propTypes: {
highlighted: React.PropTypes.boolean
},
render: function() {
return (
<article className={this.props.highlighted ? "highlighted" : "not-highlighted"}/>
);
@JonathonAshworth
JonathonAshworth / Foo.jsx
Last active March 6, 2017 04:35
Flex-based Layouts: css vs scss vs inline
// Fairly typical page layout
const Foo = props =>
<div className="page">
<div className="header">
<Logo/>
<Menu/>
<AccountOptions/>
</div>
<div className="body">