Inspired by Haskell, I wanted to see if I could replicate, using ES6 features, the repeat
function:
repeat :: a -> [a]
So as you can see in repeat.js
, I have done exactly that. However there are some caveats.
// http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery | |
const hashCode = (s) => { | |
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); | |
}; | |
const memoizeObservable = (fn) => { | |
let cache = {}; | |
return (...args) => { | |
let entryKey = hashCode(JSON.stringify(args)); |
// the two testing modules I like | |
var test = require('tape') | |
var spawn = require('tape-spawn') | |
var execspawn = require('npm-execspawn') // can spawn from require() scope, check it out! | |
// put this in outer scope so we can kill the local server at the end | |
var server | |
test('start test server', function (t) { |
#/usr/bin/env bash | |
# MIT © Sindre Sorhus - sindresorhus.com | |
# git hook to run a command after `git pull` if a specified file was changed | |
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && eval "$2" |
// App.js | |
import { Provider, Connector } from 'redux/react'; | |
import monitor from './monitor/index'; | |
const store = composeStores(stores); | |
const { dispatcher, ActionLog } = monitor(createDispatcher(store)); | |
const redux = createRedux(dispatcher); | |
export default class App { |
var fns = [function (t) { return ((t*t)/(t^t>>8))&t }, | |
function (t) { return (t>>4 & t>>8)*(t>>16&t) }, | |
function (t) { return (t>>4 & t>>8)/(t>>16&t) }, | |
function (t) { return ((2*(t&1)-1)*t)-(t>>8) }, | |
function (t) { return (t>>5)*((t&1)+(t>>16)) }, | |
function (t) { return (((Math.sin(t*t/10000000))>0.5)-1)*t }, | |
function (t) { return (((-t&t>>12)/32)-1)*t }, | |
function (t) { return (((-t&128)/64)-1)*t }, | |
function (t) { return Math.sin(t/5+(Math.sin(t/5))+t/1000)*64+t/2500 }, | |
function (t) { return Math.sin(t/5+((Math.sin(t/5)/(t/(4000*(t>>8^t>>4))))))*64+128 }, |
Inspired by Haskell, I wanted to see if I could replicate, using ES6 features, the repeat
function:
repeat :: a -> [a]
So as you can see in repeat.js
, I have done exactly that. However there are some caveats.
var RecursiveChildComponent = React.createClass({ | |
render() { | |
return <div> | |
{this.recursiveCloneChildren(this.props.children)} | |
</div> | |
}, | |
recursiveCloneChildren(children) { | |
return React.Children.map(children, child => { | |
if(!_.isObject(child)) return child; | |
var childProps = {someNew: "propToAdd"}; |
// ------------ | |
// counterStore.js | |
// ------------ | |
import { | |
INCREMENT_COUNTER, | |
DECREMENT_COUNTER | |
} from '../constants/ActionTypes'; | |
const initialState = { counter: 0 }; |
Honestly, coming from PHP, I really don't like the way dependencies are handled in JavaScript.
Using require()
or import
either gives me a singleton object, or a class that I have to
instantiate myself.
The DI container in Laravel is wonderful, and allows you to basically just ask for a dependency in a class constructor and it hands it to you. You can bind things to the container, but you can also resolve things without explicitly binding them, which I think is awesome.