Skip to content

Instantly share code, notes, and snippets.

View mauricedb's full-sized avatar

Maurice de Beijer mauricedb

View GitHub Profile
@mauricedb
mauricedb / package.json
Created November 14, 2017 08:51
Add support for Prettier
{
"private": true,
"name": "preact-workshop",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev",
"build": "preact build",
"serve": "preact build && preact serve",
"dev": "preact watch",
@mauricedb
mauricedb / app-presentation.jsx
Created March 6, 2017 16:01
Connect only to required movie data
import React, { PropTypes } from "react";
import { connect } from "react-redux";
import LoginPage from "./login-page";
import PlayingMovie from "./playing-movie";
import MainPage from "./main-page";
import AjaxLoading from "./utils/ajax-loading";
const AppPresentation = ({ user, hasMovies, playing }) => {
let component = null;
import { login } from ".";
describe("Actions", () => {
it("should create a LOGIN action", () => {
const action = login({ name: "Maurice" });
expect(action).toEqual({
type: "LOGIN",
payload: {
name: "Maurice"
import React from "react";
import ReactDOM from "react-dom";
import { createStore, applyMiddleware } from "redux";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import AppPresentation from "./app-presentation";
import reducers from "./reducers";
export const moviesLoaded = movies => ({
type: "MOVIES-LOADED",
payload: movies
});
export const loadMovies = () =>
dispatch =>
fetch("/movies.json")
.then(rsp => rsp.json())
.then(movies => dispatch(moviesLoaded(movies)));
export const moviesLoaded = movies => ({
type: "MOVIES-LOADED",
payload: movies
});
export const loadMovies = () =>
dispatch =>
fetch("/movies.json")
.then(rsp => rsp.json())
.then(movies => dispatch(moviesLoaded(movies)));
@mauricedb
mauricedb / index.js
Created March 2, 2017 14:45
Remeber the user
import React from "react";
import ReactDOM from "react-dom";
import { createStore, applyMiddleware } from "redux";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import AppContainer from "./app-container";
import reducers from "./reducers";
export const moviesLoaded = movies => ({
type: 'MOVIES-LOADED',
payload: movies,
});
export const loadMovies = () => dispatch =>
fetch('/movies.json')
.then(rsp => rsp.json())
.then(movies => dispatch(moviesLoaded(movies)));
@mauricedb
mauricedb / app-container.jsx
Last active March 2, 2017 13:19
Create store and wire up
import React, { Component } from 'react';
import AppPresentation from './app-presentation';
class AppContainer extends Component {
constructor(props) {
super(props);
this.state = {
playing: null,
allMovies: null,
@mauricedb
mauricedb / actions\index.js
Last active March 2, 2017 12:58
First action and reducer
export const login = user => ({
type: 'LOGIN',
payload: user,
});