Imagine we have a reducer to control a list of items:
function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
switch(action.type) {
case 'SHOW_ALL_ITEMS':
return action.data.items
default:
import React from 'react'; | |
import { shallow } from 'enzyme'; | |
import MyComponent from '../src/my-component'; | |
const wrapper = shallow(<MyComponent/>); | |
describe('(Component) MyComponent', () => { | |
it('renders without exploding', () => { | |
expect(wrapper).to.have.length(1); | |
}); |
import React, { Component } from "react" | |
import { Machine } from "xstate" | |
import * as PropTypes from "prop-types" | |
class FiniteMachine extends Component { | |
machine = Machine(this.props.chart) | |
state = { | |
data: this.props.reducer(undefined, { type: "@init" }), | |
machineState: this.machine.getInitialState() |
// TypeScript Fundamentals For JavaScript Developers | |
/* | |
Tutorial for JavaScript Developers wanting to get started with TypeScript. | |
Thorough walkthrough of all the basic features. | |
We will go through the basic features to gain a better understanding of the fundamentals. | |
You can uncomment the features one by one and work through this tutorial. | |
If you have any questions or feedback please connect via Twitter: | |
A. Sharif : https://twitter.com/sharifsbeat | |
*/ |
// Action creators can be impure. | |
export const addChat = ({ | |
// cuid is safer than random uuids/v4 GUIDs | |
// see usecuid.org | |
id = cuid(), | |
msg = '', | |
user = 'Anonymous', | |
timeStamp = Date.now() | |
} = {}) => ({ | |
type: ADD_CHAT, |
function Event(name){ | |
this.name = name; | |
this.callbacks = []; | |
} | |
Event.prototype.registerCallback = function(callback){ | |
this.callbacks.push(callback); | |
} | |
function Reactor(){ | |
this.events = {}; |
(function(Backbone, _) { | |
var leave; | |
_.extend(Backbone.Router.prototype, Backbone.Events, { | |
route : function(route, name, callback) { | |
var before | |
, fn = callback | |
, after; | |
Backbone.history || (Backbone.history = new Backbone.History); |
lines with $ are commands | |
### install mkvtoolnix: | |
$ brew install mkvtoolnix | |
### list content of the mkv-file: | |
$ mkvmerge -i mymoviefile.mkv | |
### what will give you: |
import { browserHistory } from 'react-router'; | |
/** | |
* @param {Object} query | |
*/ | |
export const addQuery = (query) => { | |
const location = Object.assign({}, browserHistory.getCurrentLocation()); | |
Object.assign(location.query, query); | |
browserHistory.push(location); | |
}; |
// Place user-specific overrides in this file, to ensure they're preserved | |
// when upgrading | |
{ | |
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS", "node_modules"] | |
} |