Skip to content

Instantly share code, notes, and snippets.

View fay-jai's full-sized avatar
✌️

Willson Mock fay-jai

✌️
View GitHub Profile
@fay-jai
fay-jai / module1.ts
Created April 4, 2016 03:19
Exploring Typescript Internal and External Modules
export function sayHello(name: string): string {
return `Hello, ${name}`;
}
/*
NOTE: this is the compiled JavaScript, assuming CommonJS module format
"use strict";
function sayHello(name) {
return "Hello, " + name;
}
@fay-jai
fay-jai / module2.ts
Created April 4, 2016 03:20
Exploring Typescript Internal and External Modules
namespace InternalModule {
export function add(...args: number[]): number {
return args.reduce((acc, cur) => acc + cur, 0);
}
}
export = InternalModule;
/*
NOTE: this is the compiled JavaScript, assuming CommonJS module format
@fay-jai
fay-jai / app.ts
Created April 4, 2016 03:21
Exploring Typescript Internal and External Modules
import * as SomeModule from "./module1";
import * as AnotherModule from "./module2";
console.log(SomeModule.sayHello("Willson"));
console.log(AnotherModule.add(1, 2, 3, 4));
/*
NOTE: this is the compiled JavaScript, assuming CommonJS module format
"use strict";
var SomeModule = require("./module1");
@fay-jai
fay-jai / index.html
Created April 4, 2016 03:22
Exploring Typescript Internal and External Modules
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Typescript Modules</title>
</head>
<body>
<script src="build/bundle.js"></script>
</body>
</html>
@fay-jai
fay-jai / hello_world.jsx
Created April 17, 2016 23:40
React Elements - Hello World
// This uses JSX syntax.
var helloWorld = <div>Hello World!</div>;
// And this is what the JSX syntax compiles into in JavaScript:
var helloWorld = React.createElement(
"div",
null,
"Hello World!"
);
@fay-jai
fay-jai / custom_form.jsx
Last active April 19, 2016 05:49
React Component - CustomForm
// Here's a React Component class
class CustomForm extends React.Component {
constructor(props) {
super(props);
this.state = {
inputText: "Willson"
};
this.handleInputChange = this.handleInputChange.bind(this);
@fay-jai
fay-jai / custom_form.jsx
Created April 19, 2016 06:15
Component Backing Instances in React
// Here's a React Component class
class CustomForm extends React.Component {
constructor(props) {
super(props);
this.state = {
inputText: "Willson"
};
this.handleInputChange = this.handleInputChange.bind(this);
/*
* Actions are plain old JavaScript objects. They adhere to particular
* interface in that they must have a "type" property, but aside from
* that, you can add any other property you want.
*/
const FREE_THROW = "FREE_THROW";
const TWO_POINT_SHOT = "TWO_POINT_SHOT";
// an example Action
// PSEUDO CODE BELOW
import { createStore } from "redux";
const team1Hoop = createStore( /* ignore the arguments here for now */ );
/*
* The store created above manages your entire application's state.
* You can think of the store as containing a giant JavaScript object
* where each key is a particular piece of the application state and
const team1Hoop = createStore( /* ignore the arguments here for now */ );
const twoPointer = {
type: TWO_POINT_SHOT,
payload: {
points: 2
}
};
/*