Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

Commit

Permalink
remove intent selector
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 2, 2016
1 parent b457c06 commit f77b859
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 182 deletions.
3 changes: 1 addition & 2 deletions src/app/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { routes } from './routes/all';
import { State } from './models/state';

import view from './views/app';
import viewActions from './view-actions/all';

import makeGoTo from './go-to';
import makeOther from './other';
Expand Down Expand Up @@ -39,7 +38,7 @@ export default function main() {
// for Router
routes,
// for View Renderer
'div#app', view, viewActions
'div#app', view
);
client.run();
}
82 changes: 0 additions & 82 deletions src/app/view-actions/all.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/views/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import htmlescape from 'htmlescape';
import { State } from '../models/state';
import renderApp from '../views/app';

export default function render(state: State): VTree {
export default function render(state: State, { e }: any): VTree {
return h('html', [
h('head', [
h('title', ['rally-rxjs']),
h('link', { rel: 'stylesheet', href: '/styles/index.css' }, []),
h('script', ['var INITIAL_STATE = ' + htmlescape(state) + ';'])
]),
h('body', [
renderApp(state),
renderApp(state, { e }),
h('script', { src: '/scripts/bundle.js' }, [])
])
]);
Expand Down
28 changes: 21 additions & 7 deletions src/app/views/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,41 @@ import { h, VTree } from '../../framework/view';

import { State } from '../models/state';

import { create as goTo } from '../actions/go-to';

import renderSignInPage from '../views/sign-in-page';
import renderStampRallyListPage from '../views/stamp-rally-list-page';
import renderStampRallyShowPage from '../views/stamp-rally-show-page';
import renderNotFoundPage from '../views/not-found-page';

const renderPage = (state: State): VTree => {
const renderPage = (state: State, { e }: any): VTree => {
switch (state.currentPage) {
case 'sign_in#index':
return renderSignInPage(state);
return renderSignInPage(state, { e });
case 'stamp_rallies#index':
return renderStampRallyListPage(state);
return renderStampRallyListPage(state, { e });
case 'stamp_rallies#show':
return renderStampRallyShowPage(state);
return renderStampRallyShowPage(state, { e });
default:
return renderNotFoundPage();
}
};

export default function render(state: State): VTree {
return h('div#app', [
export default function render(state: State, { e }: any): VTree {
return h('div#app', {
onclick: (event: Event) => {
event.preventDefault();
event.stopPropagation();
let node = <any> event.target;
while (node && node.tagName !== 'A') {
node = node.parentNode;
}
if (!node) return;
const path: string = node.getAttribute('href');
e(goTo(path));
}
}, [
h('h1', ['RALLY (unofficial)']),
renderPage(state)
renderPage(state, { e })
]);
}
15 changes: 11 additions & 4 deletions src/app/views/sign-in-page.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import { h, VTree } from '../../framework/view';

import { State } from '../models/state';
import { create as changeEmail } from '../actions/change-email';
import { create as changePassword } from '../actions/change-password';
import { create as signIn } from '../actions/sign-in';

export default function render(state: State): VTree {
export default function render(state: State, { e }: any): VTree {
return h('div.sign-in-page', [
h('label', [
'email',
h('input.email', {
type: 'email',
name: 'email',
value: state.signIn.email
value: state.signIn.email,
onchange: ({ target: { value } }) => e(changeEmail(value))
}, []),
]),
h('label', [
'password',
h('input.password', {
type: 'password',
name: 'password',
value: state.signIn.password
value: state.signIn.password,
onchange: ({ target: { value } }) => e(changePassword(value))
}, [])
]),
h('button.sign-in', ['sign in'])
h('button.sign-in', {
onclick: () => e(signIn())
}, ['sign in'])
]);
}
21 changes: 16 additions & 5 deletions src/app/views/spot-form-view.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { h, VTree } from '../../framework/view';

import { SpotForm } from '../models/spot-form';
import { create as addSpot } from '../actions/add-spot';
import {
create as changeSpotFormName
} from '../actions/change-spot-form-name';

const labeledTextBox = (name: string, value: string): VTree => {
const labeledTextBox = (name: string, value: string, e: any): VTree => {
return h('label', [
name,
h('input.' + name, {
type: 'text',
name,
value
value,
onchange: ({ target: { value } }) => e(changeSpotFormName(value))
}, []),
]);
};

export default function render(state: SpotForm): VTree {
export default function render(state: SpotForm, { e }: any): VTree {
return h('form.spot', [
labeledTextBox('name', state.name),
h('button.add-spot', ['add spot'])
labeledTextBox('name', state.name, e),
h('button.add-spot', {
onclick: (event: Event) => {
event.preventDefault();
event.stopPropagation();
e(addSpot());
}
}, ['add spot'])
]);
};
23 changes: 18 additions & 5 deletions src/app/views/stamp-rally-form-view.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { h, VTree } from '../../framework/view';

import { StampRallyForm } from '../models/stamp-rally-form';
import { create as addStampRallyAction } from '../actions/add-stamp-rally';
import {
create as changeStampRallyFormName
} from '../actions/change-stamp-rally-form-name';

const labeledTextBox = (name: string, value: string): VTree => {
const labeledTextBox = (name: string, value: string, e: any): VTree => {
return h('label', [
name,
h('input.' + name, {
type: 'text',
name,
value
value,
onchange: ({ target: { value } }) => {
e(changeStampRallyFormName(value))
}
}, []),
]);
};

export default function render(state: StampRallyForm): VTree {
export default function render(state: StampRallyForm, { e }: any): VTree {
return h('form.stamp-rally', [
labeledTextBox('name', state.name),
h('button.add-stamp-rally', ['add stamp-rally'])
labeledTextBox('name', state.name, e),
h('button.add-stamp-rally', {
onclick: (event: Event) => {
event.preventDefault();
event.stopPropagation();
e(addStampRallyAction());
}
}, ['add stamp-rally'])
]);
};
4 changes: 2 additions & 2 deletions src/app/views/stamp-rally-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { h, VTree } from '../../framework/view';
import { State } from '../models/state';
import renderStampRallyFormView from '../views/stamp-rally-form-view';

export default function render(state: State): VTree {
export default function render(state: State, { e }: any): VTree {
return h('div.stamp-rally-list-page', [
h('ul', state.stampRallies.map(stampRally => {
const href = '/stamp_rallies/' + stampRally.name;
Expand All @@ -16,6 +16,6 @@ export default function render(state: State): VTree {
])
]);
})),
renderStampRallyFormView(state.stampRallyForm)
renderStampRallyFormView(state.stampRallyForm, { e })
]);
}
4 changes: 2 additions & 2 deletions src/app/views/stamp-rally-show-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { h, VTree } from '../../framework/view';
import { State } from '../models/state';
import renderSpotFormView from '../views/spot-form-view';

export default function render(state: State): VTree {
export default function render(state: State, { e }: any): VTree {
return h('div.stamp-rally-show-page', [
(
state.stampRally
Expand All @@ -17,6 +17,6 @@ export default function render(state: State): VTree {
spot.tagline
]);
})),
renderSpotFormView(state.spotForm)
renderSpotFormView(state.spotForm, { e })
]);
}
16 changes: 5 additions & 11 deletions src/framework/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { from as render$, is as isRender } from '../app/actions/render';

class Client<State> {
private viewRootSelector: string;
private view: (state: State) => VTree;
private viewAction: (dom: DOM) => O<A<string>>;
private view: (state: State, options: any) => VTree;
private app: (
action$: O<A<any>>,
options: any
Expand All @@ -26,19 +25,18 @@ class Client<State> {
routes: Route[],
// for View Renderer
viewRootSelector: string,
view: (state: State) => VTree,
viewAction: (dom: DOM) => O<A<any>>
view: (state: State, options: any) => VTree
) {
this.viewRootSelector = viewRootSelector;
this.view = view;
this.viewAction = viewAction;
this.app = app;
this.router = new Router(routes);
}

run(): void {
const dom = new DOM(this.viewRootSelector);
const state: State = (<any> window).INITIAL_STATE;
const e = (action: A<any>): void => subject.next(action);
const subject = new Subject<A<any>>();
const history = new HistoryRouter(this.router, subject);
const fs = [
Expand All @@ -51,7 +49,7 @@ class Client<State> {
(action: A<any>): A<any> => {
if (!isRender(action)) return action;
const state: any = action.params; // FIXME
const vtree = this.view(state);
const vtree = this.view(state, { e });
dom.renderToDOM(vtree);
return { type: 'noop' };
}
Expand All @@ -66,11 +64,7 @@ class Client<State> {
)
.filter(action => action && action.type !== 'noop')
.share();
const app$: O<A<any>> = Observable
.merge(
this.app(action$, { state }),
this.viewAction(dom)
);
const app$ = this.app(action$, { state });
history.start();
app$.subscribe(action => { setTimeout(() => subject.next(action)); });
}
Expand Down
Loading

0 comments on commit f77b859

Please sign in to comment.