Skip to content

Commit

Permalink
Added day 1 not resolved and sync with trello as practice.
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaoncode committed Jul 11, 2016
1 parent fd16ec6 commit 3fb9bcb
Show file tree
Hide file tree
Showing 34 changed files with 5,844 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ It will be divided in 6 days of learning and teaching. Learning because it is al
- Typescript

- Jest

#Requirements to start typescript

Follow this steps :)

https://www.typescriptlang.org/docs/handbook/react-&-webpack.html

And then just install the tools you need for your favorite IDE, I am using Atom at the moment.
2 changes: 2 additions & 0 deletions day-1-not-resolved/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
29 changes: 29 additions & 0 deletions day-1-not-resolved/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Synopsis

First day on training with react, typescript, flux and webpack.

#Objectives

Learn as much as possible on the latest trends, and provide to my partners some knowledge and tools they can use.

- Introduction to ReactJs

- Components

- Props and State

- Communication between Components

- The Finer Points

- Thinking in React

- Flux Architecture

- Questions

#Contributors

Juan José García

wwww.jotaoncode.com
37 changes: 37 additions & 0 deletions day-1-not-resolved/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Animation lists!</title>
<style media="screen">
.stop {
display: none;
}
.play: {
display: block;
}
.list-to-play {
width: 20%;
float: left;
}
.animation {
width: 60%;
float: left;
}
.full-list {
width: 20%;
float: left;
}
</style>
</head>
<body>
<div id="example"></div>

<!-- Dependencies -->
<script src="./node_modules/react/dist/react.js"></script>
<script src="./node_modules/react-dom/dist/react-dom.js"></script>

<!-- Main -->
<script src="./dist/bundle.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions day-1-not-resolved/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "proj",
"version": "1.0.0",
"description": "ejemplo",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jotaoncode",
"license": "ISC",
"dependencies": {
"classnames": "^2.2.5",
"events": "^1.1.1",
"flux": "^2.1.1",
"material-ui": "^0.15.1",
"react": "^15.2.0",
"react-addons-update": "^15.2.1",
"react-dom": "^15.2.0",
"ts-eventemitter": "^0.1.0"
},
"devDependencies": {
"retyped-classnames-tsd-ambient": "0.0.0-0",
"source-map-loader": "^0.1.5",
"ts-loader": "^0.8.2"
}
}
11 changes: 11 additions & 0 deletions day-1-not-resolved/src/actions/CommonAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IStyleLearntState } from '../stores/dancingStyles';

class CommonAction {
type: string
msg: IStyleLearntState
constructor (type: string, msg: IStyleLearntState) {
this.type = type;
this.msg = msg;
}
}
export default CommonAction;
11 changes: 11 additions & 0 deletions day-1-not-resolved/src/actions/PlayAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IStyleLearntState } from "../stores/dancingStyles";

class PlayAction {
type: string
data: IStyleLearntState
constructor (type: string, dancingStyle: IStyleLearntState) {
this.type = type;
this.data = dancingStyle;
}
}
export default PlayAction;
20 changes: 20 additions & 0 deletions day-1-not-resolved/src/actions/learningActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import appDispatcher from '../dispatcher/appDispatcher';
import CommonAction from '../actions/CommonAction';
import { IStyleLearntState } from '../stores/dancingStyles';

class LearningActions {
forgetDancingStyle(dancingStyle: IStyleLearntState) {
//TODO 11: Dipatch dancing style with a new instance Common Action and the action "forgetDancingStyle"

}
learnDancingStyle(dancingStyle: IStyleLearntState) {
//TODO 10: Dipatch dancing style with a new instance Common Action and the action "learnDancingStyle"

}
setPlayingStyle(dancingStyle: IStyleLearntState) {
//TODO 10: Dipatch dancing style with a new instance Common Action and the action "setPlayingStyle"

}
}

export default new LearningActions();
11 changes: 11 additions & 0 deletions day-1-not-resolved/src/actions/playActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import appDispatcher from '../dispatcher/appDispatcher';
import PlayAction from '../actions/PlayAction';
import { IStyleLearntState } from "../stores/dancingStyles";

class PlayActions {
toggleAnimation(dancingStyle: IStyleLearntState) {
//TODO 10: Dipatch dancing style with a new instance Play Action and the action "toggleDancing"
}
}

export default new PlayActions();
33 changes: 33 additions & 0 deletions day-1-not-resolved/src/components/animation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from "react";
import playActions from "../actions/playActions";
import dancingControls from '../stores/dancingControls';
import dancingStyles from '../stores/dancingStyles';
import {IStyleLearntState} from '../stores/dancingStyles';
export interface IAnimationProps { }
export interface IAnimationState { isPlaying: boolean; selectedStyle: IStyleLearntState}

export class Animation extends React.Component<IAnimationProps, IAnimationState> {
constructor() {
super();
this.state = {
isPlaying: dancingControls.isPlaying(),
selectedStyle: dancingControls.getSelectedStyle()
};
}
componentWillMount() {
//TODO 6: Subscribe to dancingControls "change" event with the onChange function
}
componentWillUnmount() {
//TODO 6: Unsubscribe from dancingControls "change" event with the onChange function
}
onChange() {
//TODO 6: Set state of animation component check setState method please
}
render() {
let classPlaying = this.state.isPlaying ? 'play': 'stop';
let gifRef = this.state.selectedStyle ? this.state.selectedStyle.href : null;
return <div>
<iframe src={gifRef} className={classPlaying}></iframe>
</div>;
}
}
34 changes: 34 additions & 0 deletions day-1-not-resolved/src/components/animations/fullList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from "react";
import { ListItem } from "./listItem";
import { IStyleLearntState, IStylesLearntState } from '../../stores/dancingStyles';
import dancingStyles from '../../stores/dancingStyles';

export interface IStylesLearntProps { }

export class FullList extends React.Component<IStylesLearntProps, IStylesLearntState> {
constructor() {
super();
this.state = {
stylesLearnt: dancingStyles.getDancingLearnt(),
existingStyles: dancingStyles.getDancingStyles()
};
}
componentWillMount() {
//TODO 2: Subscribe to dancingStyles change event with the onChange function
}
componentWillUnmount() {
//TODO 2: Unsubscribe to dancing styles change event with the onChange function
}
onChange() {
//TODO 2: Change the state of Playables by setting a new state to the component
//Check for setState method.
}
public render() {
var styles = this.state.existingStyles.map((style: IStyleLearntState, index: number) => {
return (<ListItem href={style.href} song={style.song} style={style.style} key={index}/>);
});
return <ul>
{ styles }
</ul>;
}
}
10 changes: 10 additions & 0 deletions day-1-not-resolved/src/components/animations/listItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from "react";
import learningActions from "../../actions/learningActions";
import { IStyleLearntState } from '../../stores/dancingStyles';

export class ListItem extends React.Component<IStyleLearntState, void> {
//TODO 3: Implement a method to call an action that a remove this item and sets it to playable
render() {
return <li>{this.props.song}</li>;
}
}
25 changes: 25 additions & 0 deletions day-1-not-resolved/src/components/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react";
import { Animation } from './animation';
import { ListToPlay } from './playable/playables';
import { FullList } from './animations/fullList';

export interface ApplicationProps { }

export class Application extends React.Component<ApplicationProps, {}> {
render() {
return <div>
<section className="list-to-play">
<h1>Playable List</h1>
<ListToPlay/>
</section>
<section className="animation">
<h1>Animation</h1>
<Animation />
</section>
<section className="full-list">
<h1>Choosing List</h1>
<FullList/>
</section>
</div>;
}
}
22 changes: 22 additions & 0 deletions day-1-not-resolved/src/components/playable/playable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from "react";
import learningActions from "../../actions/learningActions";
import dancingControls from '../../stores/dancingControls';
import playActions from "../../actions/playActions";
import { IStyleLearntState } from "../../stores/dancingStyles";

export class Playable extends React.Component<IStyleLearntState, void> {
//TODO 5 Implement Forget Dancing Style button Remove
//TODO 4 Implement Toggle Play button-play
render() {
let isPlayingNow = dancingControls.isPlaying() && dancingControls.getSelectedStyle().style === this.props.style;
let textButton = "Play!";
if (isPlayingNow) {
textButton = "Stop!";
}
return <li>
{this.props.song}
<button className="button-play">{textButton}</button>
<button>Remove</button>
</li>;
}
}
34 changes: 34 additions & 0 deletions day-1-not-resolved/src/components/playable/playables.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from "react";
import { Playable } from './playable';
import { IStyleLearntState, IStylesLearntState } from '../../stores/dancingStyles';
import dancingStyle from '../../stores/dancingStyles';

export interface IStylesLearntProps { }

export class ListToPlay extends React.Component<IStylesLearntProps, IStylesLearntState> {
constructor() {
super();
this.state = {
stylesLearnt: dancingStyle.getDancingLearnt(),
existingStyles: dancingStyle.getDancingStyles()
};
}
componentWillMount() {
//TODO 1: Subscribe to dancingStyle change event
}
componentWillUnmount() {
//TODO 1: Unsubscribe to dancingStyle change event
}
onChange() {
//TODO 1: Change the state of Playables by setting a new state to the component
//Check for setState method.
}
public render() {
var styles = this.state.stylesLearnt.map((style: IStyleLearntState, index: number) => {
return (<Playable href={style.href} song={style.song} style={style.style} key={index}/>);
});
return <ul>
{ styles }
</ul>;
}
}
Empty file.
4 changes: 4 additions & 0 deletions day-1-not-resolved/src/dispatcher/appDispatcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as flux from 'flux';
//I work as a HUB, dispatching actions to those who needs it, caugh caugh stores...
const appDispatcher = new flux.Dispatcher<any>()
export default appDispatcher;
9 changes: 9 additions & 0 deletions day-1-not-resolved/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from "react";
import * as ReactDOM from "react-dom";

import { Application } from "./components/application";

ReactDOM.render(
<Application />,
document.getElementById("example")
);
52 changes: 52 additions & 0 deletions day-1-not-resolved/src/stores/dancingControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as events from 'events';
import PlayAction from '../actions/PlayAction';
import appDispatcher from '../dispatcher/appDispatcher';
import { IStyleLearntState } from '../stores/dancingStyles';
/**
* Mocked values for dancing styles
*/
let isPlaying = false;

const CHANGE_EVENT = 'change';
let actualStyle : IStyleLearntState;
/**
* I am in charge of informing the component a change event
*/
class PlayingActions extends events.EventEmitter {
//Add callback to change event
addChangeListener(cb:Function) {
this.on(CHANGE_EVENT, cb);
}
//Remove callback to change event
removeChangeListener(cb:Function) {
this.removeListener(CHANGE_EVENT, cb);
}
isPlaying() {
return isPlaying;
}

toggleAnimation(dancingStyle: IStyleLearntState) {
//TODO 9: Add dancing style as actual style variable when it is playing
//Toggle is Playing value
}
getSelectedStyle() {
return actualStyle;
}
emitChange() {
this.emit(CHANGE_EVENT);
}
}
const playingStore = new PlayingActions();

appDispatcher.register(function (action: PlayAction) {
switch(action.type) {
case "toggleDancing":
//TODO 9: Call toggle Animation
break;
default:
//No op
}
playingStore.emitChange();
});

export default playingStore;
Loading

0 comments on commit 3fb9bcb

Please sign in to comment.