import React from 'react'; import ReactDOM from 'react-dom'; import {createStore} from 'redux'; import {Map} from 'immutable'; class PixelatedComponent extends React.Component { _updateStateFromStore() { this.setState(this.props.store.getState().toJS()); } componentWillMount() { console.debug('mounting', this); this.unsubscribe = this.props.store.subscribe(() => this._updateStateFromStore()); this._updateStateFromStore(); } componentWillUnmount() { console.debug('unmounting', this); this.unsubscribe() } } class InviteCodeForm extends PixelatedComponent { render() { return (
); } _handleClick(event) { event.stopPropagation(); event.preventDefault(); this.props.store.dispatch({type: 'SUBMIT_INVITE_CODE'}); } } class CreateAccountForm extends PixelatedComponent { render() { return (
@domain.com
); } _handleClick(event) { event.stopPropagation(); event.preventDefault(); this.props.store.dispatch({type: 'SUBMIT_CREATE_ACCOUNT'}); } } class BackupEmailForm extends PixelatedComponent { render() { return (
@domain.com
); } _handleClick(event) { event.stopPropagation(); event.preventDefault(); this.props.store.dispatch({type: 'SUBMIT_CREATE_ACCOUNT'}); } } class SignUp extends PixelatedComponent { render() { return (

{this.state.header}

{this.state.summary}

{this._form()}
); } _form() { switch(this.state.form) { case 'invite_code': return ; case 'create_account': return ; case 'backup_email': return ; default: throw Exception('TODO'); } } } const initialState = new Map({ form: 'invite_code', header: 'Welcome', summary: ['Do you have an invite code?',
, 'Type it below'], }); const store = createStore((state=initialState, action) => { switch (action.type) { case 'SUBMIT_INVITE_CODE': return state.merge({ form: 'create_account', header: 'Create your account', summary: 'Choose your username, and be careful about your password, it must be strong and easy to remember. If you have a password manager, we strongly advise you to use one.', }); case 'SUBMIT_CREATE_ACCOUNT': return state.merge({ form: 'backup_email', header: 'In case you lose your password...', summary: 'Set up a backup email account. You\'ll receive an email with a code so you can recover your account in the future, other will be sent to your account administrator.', }); default: return state; } }); ReactDOM.render( , document.getElementById('app') );