Skip to content

Commit

Permalink
Merge pull request #3 from pfgray/better_demos
Browse files Browse the repository at this point in the history
Adding better demos
  • Loading branch information
pfgray authored Jun 22, 2018
2 parents 1489edd + b944a9e commit 91e57fc
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 262 deletions.
6 changes: 3 additions & 3 deletions demo/AllDemo.tsx → demo/demos/AllDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { withState } from '../src/lib/withState';
import { all } from '../src/ChainableComponent';
import Step from './Step';
import { withState } from '../../src/lib/withState';
import { all } from '../../src/ChainableComponent';
import Step from '../Step';

export const WithStateDemo =
all([
Expand Down
4 changes: 2 additions & 2 deletions demo/ContextDemo.tsx → demo/demos/ContextDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { fromRenderProp } from '../src/ChainableComponent';
import { fromRenderProp } from '../../src/ChainableComponent';
// how to create a context hoc?
import Step from './Step';
import Step from '../Step';
const { Consumer, Provider } = React.createContext("Default Value");

const withContext = fromRenderProp(Consumer);
Expand Down
31 changes: 31 additions & 0 deletions demo/demos/DoDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { withState } from '../../src/lib/withState';
import { all, Do, ChainableComponent } from '../../src/ChainableComponent';
import Step from '../Step';

export const DoDemo = () =>
Do(function*() {
const a = yield withState({initial: 'string value'});
const b = yield withState({initial: 8432});
return [a, b];
})
.ap(([a, b]) => (
<div>
{/* a.value is inferred as a string */}
<div>a: {a.value} <button onClick={() => a.update(a.value + 1)}>+</button></div>

{/* b.value through f.value is inferred as a number */}
<div>b: {b.value} <button onClick={() => b.update(b.value + 1)}>+</button></div>
</div>
));

export default () => (
<Step title="Do Demo">
<pre className='code-sample'>
{`import { withState, all } from 'chainable-components';`}
</pre>
<DoDemo />
</Step>
);


25 changes: 25 additions & 0 deletions demo/demos/FromApDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react';
import { withState } from '../../src/lib/withState';
import { all, fromAp } from '../../src/ChainableComponent';
import Step from '../Step';

export const WithStateDemo =
fromAp((ap: (a: number) => React.ReactNode) => (
function() {
return <div>Applied: {ap(5)}</div>
}
))
.ap(a => (
<div>wait, wuuuut: {a}</div>
));

export default () => (
<Step title="FromAp Demo">
<pre className='code-sample'>
{`import { withState, all } from 'chainable-components';`}
</pre>
{WithStateDemo}
</Step>
);


4 changes: 2 additions & 2 deletions demo/ReactRouterDemo.tsx → demo/demos/ReactRouterDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';;
import { Route, Router } from 'react-router';
import { fromRenderProp } from '../src/ChainableComponent';
import Step from './Step';
import { fromRenderProp } from '../../src/ChainableComponent';
import Step from '../Step';
import createBrowserHistory from 'history/createBrowserHistory';

const customHistory = createBrowserHistory();
Expand Down
7 changes: 3 additions & 4 deletions demo/WithStateDemo.tsx → demo/demos/WithStateDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as React from 'react';
import { withState } from '../src/lib/withState';
import Step from './Step';
import { withState } from '../../src/lib/withState';
import Step from '../Step';
// import { all } from '../src/ChainableComponent';

export const WithStateDemo =
withState({ initial: 0 }).chain(outer =>
withState({ initial: 16 }).map(inner =>
({ inner, outer })
)
)
.ap(({ inner, outer }) => (
).ap(({ inner, outer }) => (
<div>
<div>Outer: {outer.value} <button onClick={() => outer.update(outer.value + 1)}>+</button></div>
<div>Inner: {inner.value} <button onClick={() => inner.update(inner.value + 1)}>+</button></div>
Expand Down
12 changes: 7 additions & 5 deletions demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import '../styles/index.less';

import './demo.less';

const Demos = require.context('./', false, /\.*Demo\.tsx$/);
const Demos = require.context('./demos', true, /\.*\.tsx$/);

const APP_ELEMENT = document.getElementById('app')!;
const APP_ELEMENT = document.body;
const render = (Component: React.ComponentType<any>) => {
ReactDOM.render(
<AppContainer>
<div id="app">
<Component/>
</div>
</AppContainer>,
APP_ELEMENT,
);
Expand All @@ -25,7 +27,7 @@ render(() => <div>

declare var module: any;
if (module.hot) {
module.hot.accept('./Demo', () => {
render(require('./Demo').Demo);
});
// module.hot.accept('./Demo', () => {
// render(require('./Demo').Demo);
// });
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/html-webpack-plugin": "^2.28.0",
"@types/html-webpack-plugin": "^2.30.3",
"@types/mocha": "^2.2.43",
"@types/react": "^16.0.10",
"@types/react-dom": "^16.0.1",
Expand All @@ -39,7 +39,7 @@
"formik": "^0.11.11",
"history": "^4.7.2",
"html-loader": "^0.5.1",
"html-webpack-plugin": "^2.30.1",
"html-webpack-plugin": "^3.2.0",
"jsdom": "^11.3.0",
"jsdom-global": "^3.0.2",
"less": "^3.0.0-alpha.3",
Expand All @@ -59,7 +59,7 @@
"typescript": "^2.5.3",
"webpack": "^4.0.0",
"webpack-cli": "^3.0.3",
"webpack-dev-server": "^2.9.1"
"webpack-dev-server": "^3.1.4"
},
"dependencies": {},
"peerDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { CONSTANTS } from './constants';

// tslint:disable-next-line no-var-requires

console.log('wuuut:', CONSTANTS.APP_ENTRY);
const config: webpack.Configuration = {
entry: {
'chainable-components': CONSTANTS.APP_ENTRY
},
entry: CONSTANTS.APP_ENTRY,
output: {
filename: 'chainable-components.js',
path: CONSTANTS.DOCS_DIR,
Expand Down
14 changes: 8 additions & 6 deletions webpack/hot.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as webpack from 'webpack';
import config from './base';
import { CONSTANTS } from './constants';
const HtmlWebpackPlugin = require('html-webpack-plugin')

const baseEntry = config.entry as webpack.Entry;
const entry = {
...baseEntry,
app: [
const entry = [
// activate HMR for React
'react-hot-loader/patch',

Expand All @@ -16,9 +15,8 @@ const entry = {
// bundle the client for hot reloading
// only- means to only hot reload for successful updates
'webpack/hot/only-dev-server',
baseEntry.app as string,
],
};
baseEntry,
];

const rules = (config.module as any).rules.map((loaderConf: any) => {
if (loaderConf.test.test('test.ts')) {
Expand All @@ -45,6 +43,9 @@ const plugins = [
'process.env.NODE_ENV': 'null',
}),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: '🔗-able Components'
})
];

const hotConfig = {
Expand All @@ -53,6 +54,7 @@ const hotConfig = {
module,
plugins,
devtool: '#cheap-module-source-map',
mode: 'development',
devServer: {
contentBase: CONSTANTS.DOCS_DIR,
historyApiFallback: true,
Expand Down
Loading

0 comments on commit 91e57fc

Please sign in to comment.