Skip to content

Commit

Permalink
контроллер будет знать меньше, переименовал события вью (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geksanit committed Feb 1, 2018
1 parent 01d9f36 commit 64fa6cd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
10 changes: 5 additions & 5 deletions frontend/mvc/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ class Controller {
this.view = view;
this.fps = 1;
this.setSubscription();
this.view.initTable(this.model.matrix);// начальная отрисовка
this.view.initTable(this.model.matrix);
this.setRunning(false);
}
setSubscription():void {
this.model.matrixChanged.attach((sender, obj) => {
if (obj.resized) { this.view.initTable(obj.matrix); }
else { this.view.changeTable(obj.matrix); }
});
this.view.tableClicked.attach((sender, { row, cell }) => {
this.view.tableCellChanged.attach((sender, { row, cell }) => {
this.model.toggleCell(row, cell);
});
this.view.startClicked.attach(() => {
this.view.startEvent.attach(() => {
this.setRunning(true);
this.anim();
});
this.view.pauseClicked.attach(() => {
this.view.pauseEvent.attach(() => {
this.setRunning(false);
});
this.view.clearClicked.attach(() => {
this.view.clearEvent.attach(() => {
this.model.clearMatrix();
this.setRunning(false);
});
Expand Down
2 changes: 0 additions & 2 deletions frontend/mvc/model/IModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import IEventSender from '../utils/IEventSender';
interface IModel {
matrix: boolean[][];
matrixChanged: IEventSender;
rows: number;
columns: number;
setWidthMatrix(newValue: number): void;
setHeightMatrix(newValue: number): void;
clearMatrix(): void;
Expand Down
8 changes: 4 additions & 4 deletions frontend/mvc/view/IView.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import IEventSender from '../utils/IEventSender';

interface IView {
tableClicked: IEventSender;
startClicked: IEventSender;
pauseClicked: IEventSender;
clearClicked: IEventSender;
tableCellChanged: IEventSender;
startEvent: IEventSender;
pauseEvent: IEventSender;
clearEvent: IEventSender;
widthChanged: IEventSender;
heightChanged: IEventSender;
speedChanged: IEventSender;
Expand Down
24 changes: 12 additions & 12 deletions frontend/mvc/view/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class View implements IView{
$sliderHeight: JQuery;
$status: JQuery;

tableClicked: EventSender;
startClicked: EventSender;
pauseClicked: EventSender;
clearClicked: EventSender;
tableCellChanged: EventSender;
startEvent: EventSender;
pauseEvent: EventSender;
clearEvent: EventSender;
widthChanged: EventSender;
heightChanged: EventSender;
speedChanged: EventSender;
Expand All @@ -39,10 +39,10 @@ class View implements IView{
this.$status = this.$controls.find('.js-game__status');
}
initEvents(): void {
this.tableClicked = new EventSender(this);
this.startClicked = new EventSender(this);
this.pauseClicked = new EventSender(this);
this.clearClicked = new EventSender(this);
this.tableCellChanged = new EventSender(this);
this.startEvent = new EventSender(this);
this.pauseEvent = new EventSender(this);
this.clearEvent = new EventSender(this);
this.widthChanged = new EventSender(this);
this.heightChanged = new EventSender(this);
this.speedChanged = new EventSender(this);
Expand All @@ -51,16 +51,16 @@ class View implements IView{
this.$table.on('click.view', 'td', ({ target }) => {
const cell: number = $(target).prop('cellIndex') as number;
const row: number = $(target.parentElement).prop('sectionRowIndex') as number;
this.tableClicked.notify({ row, cell });
this.tableCellChanged.notify({ row, cell });
});
this.$buttonStart.on('click.view', () => {
this.startClicked.notify({});
this.startEvent.notify({});
});
this.$buttonPause.on('click.view', () => {
this.pauseClicked.notify({});
this.pauseEvent.notify({});
});
this.$buttonClear.on('click.view', () => {
this.clearClicked.notify({});
this.clearEvent.notify({});
});
this.$sliderSpeed.on('change.view', ({ target }) => {
const value: number = Number($(target).val());
Expand Down

0 comments on commit 64fa6cd

Please sign in to comment.