Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix: restore event handler props
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 10, 2018
1 parent c7a79b8 commit f78b70e
Show file tree
Hide file tree
Showing 51 changed files with 711 additions and 660 deletions.
64 changes: 64 additions & 0 deletions src/alva-util/compute-difference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export interface Difference<T> {
added: AddItem<T>[];
changed: ChangeItem<T>[];
removed: RemoveItem<T>[];
}

export interface AddItem<T> {
before: undefined;
after: T;
}

export interface ChangeItem<T> {
before: T;
after: T;
}

export interface RemoveItem<T> {
before: T;
after: undefined;
}

export type Diffable<T> = Identifyable & Equalifyable<T>;

export interface Identifyable {
getId(): string;
}

export interface Equalifyable<T> {
equals(this: T, a: T): boolean;
}

export function computeDifference<T extends Diffable<T>>(init: {
before: T[];
after: T[];
}): Difference<T> {
const { before, after } = init;

const added = after.filter(
afterItem => !before.some(beforeItem => afterItem.getId() === beforeItem.getId())
);

const removed = before
.filter(beforeItem => !added.some(addItem => addItem.getId() === beforeItem.getId()))
.filter(beforeItem => !after.some(afterItem => afterItem.getId() === beforeItem.getId()));

const changed = before
.filter(beforeItem => !added.some(addItem => addItem.getId() === beforeItem.getId()))
.filter(beforeItem => !removed.some(addItem => addItem.getId() === beforeItem.getId()))
.filter(beforeItem => {
const matchingAfterItem = after.find(
afterItem => afterItem.getId() === beforeItem.getId()
);
return matchingAfterItem && !beforeItem.equals(matchingAfterItem);
});

return {
added: added.map(item => ({ before: undefined, after: item })),
changed: changed.map(beforeItem => ({
after: after.find(afterItem => afterItem.getId() === beforeItem.getId()) as T,
before: beforeItem
})),
removed: removed.map(item => ({ before: item, after: undefined }))
};
}
1 change: 1 addition & 0 deletions src/alva-util/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './compute-difference';
export * from './ensure-array';
export * from './guess-name';
export * from './noop';
Expand Down
8 changes: 4 additions & 4 deletions src/container/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Sender from '../sender/client';
import * as Components from '../components';
import { ConnectPaneContainer } from './connect-pane-container';
import { ElementList } from './element-list';
import { ServerMessageType } from '../message';
import { MessageType } from '../message';
import * as MobxReact from 'mobx-react';
import { PageListContainer } from './page-list/page-list-container';
import { PatternListContainer } from './pattern-list';
Expand Down Expand Up @@ -46,14 +46,14 @@ export class App extends React.Component {
<SplashScreenContainer
onPrimaryButtonClick={() => {
Sender.send({
type: ServerMessageType.CreateNewFileRequest,
type: MessageType.CreateNewFileRequest,
id: uuid.v4(),
payload: undefined
});
}}
onSecondaryButtonClick={() => {
Sender.send({
type: ServerMessageType.OpenFileRequest,
type: MessageType.OpenFileRequest,
id: uuid.v4(),
payload: undefined
});
Expand Down Expand Up @@ -137,7 +137,7 @@ export class App extends React.Component {
onPrimaryButtonClick={() => props.store.connectPatternLibrary()}
onSecondaryButtonClick={() =>
Sender.send({
type: ServerMessageType.OpenExternalURL,
type: MessageType.OpenExternalURL,
id: uuid.v4(),
payload: 'http://meetalva.github.io/example/example.alva'
})
Expand Down
6 changes: 3 additions & 3 deletions src/container/chrome/chrome-container.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AlvaUtil from '../../alva-util';
import { ChromeSwitch } from './chrome-switch';
import { BugReport, Chrome, CopySize, ViewSwitch } from '../../components';
import { ServerMessageType } from '../../message';
import { MessageType } from '../../message';
import * as MobxReact from 'mobx-react';
import { Page } from '../../model';
import * as React from 'react';
Expand Down Expand Up @@ -44,7 +44,7 @@ export const ChromeContainer = MobxReact.inject('store')(
<Chrome
onDoubleClick={() => {
Sender.send({
type: ServerMessageType.Maximize,
type: MessageType.Maximize,
id: uuid.v4(),
payload: undefined
});
Expand All @@ -69,7 +69,7 @@ export const ChromeContainer = MobxReact.inject('store')(
title="Found a bug?"
onClick={() => {
Sender.send({
type: ServerMessageType.OpenExternalURL,
type: MessageType.OpenExternalURL,
id: uuid.v4(),
payload: 'https://github.com/meetalva/alva/labels/type%3A%20bug'
});
Expand Down
4 changes: 2 additions & 2 deletions src/container/page-list/page-list-container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sender from '../../sender/client';
import { AddPageButton, Layout, LayoutWrap } from '../../components';
import { ServerMessageType } from '../../message';
import { MessageType } from '../../message';
import * as MobxReact from 'mobx-react';
import { PageTileContainer } from './page-tile-container';
import * as React from 'react';
Expand Down Expand Up @@ -35,7 +35,7 @@ export const PageListContainer: React.StatelessComponent = MobxReact.inject('sto
Sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.CreateNewPage
type: MessageType.CreateNewPage
})
}
/>
Expand Down
17 changes: 11 additions & 6 deletions src/container/property-list/event-handler-property-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ export class EventHandlerPropertyView extends React.Component<EventHandlerProper
return;
}

const elementAction = new Model.ElementAction({
id: uuid.v4(),
payload: '',
storeActionId: selectedAction.getId(),
storePropertyId: selectedAction.getUserStorePropertyId() || ''
});
const elementAction = new Model.ElementAction(
{
id: uuid.v4(),
payload: '',
storeActionId: selectedAction.getId(),
storePropertyId: selectedAction.getUserStorePropertyId() || ''
},
{
userStore: project.getUserStore()
}
);

project.addElementAction(elementAction);
props.elementProperty.setValue(elementAction.getId());
Expand Down
6 changes: 3 additions & 3 deletions src/container/property-list/property-list-item.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sender from '../../sender/client';
import * as Component from '../../components';
import { EventHandlerPropertyView } from './event-handler-property-view';
import { ServerMessageType } from '../../message';
import { MessageType } from '../../message';
import * as MobxReact from 'mobx-react';
import { ElementProperty, PatternEnumProperty } from '../../model';
import * as React from 'react';
Expand Down Expand Up @@ -100,7 +100,7 @@ export class PropertyListItem extends React.Component<PropertyListItemProps> {

Sender.receive(message => {
if (
message.type === ServerMessageType.AssetReadResponse &&
message.type === MessageType.AssetReadResponse &&
message.id === transactionId
) {
property.setValue(message.payload);
Expand All @@ -111,7 +111,7 @@ export class PropertyListItem extends React.Component<PropertyListItemProps> {
Sender.send({
id: transactionId,
payload: undefined,
type: ServerMessageType.AssetReadRequest
type: MessageType.AssetReadRequest
});
}}
placeholder="Or enter URL"
Expand Down
75 changes: 0 additions & 75 deletions src/electron/create-client-message-handler.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/electron/create-main-menu/create-app-menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Electron from 'electron';
import { Sender } from '../../sender/server';
import { ServerMessageType } from '../../message';
import { MessageType } from '../../message';
import * as Types from '../../types';
import * as uuid from 'uuid';

Expand Down Expand Up @@ -29,7 +29,7 @@ export function createAppMenu(
injecton.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.CheckForUpdatesRequest
type: MessageType.CheckForUpdatesRequest
});
}
},
Expand Down
16 changes: 8 additions & 8 deletions src/electron/create-main-menu/create-edit-menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Electron from 'electron';
import { ServerMessageType } from '../../message';
import { MessageType } from '../../message';
import * as Model from '../../model';
import { Sender } from '../../sender/server';
import * as Types from '../../types';
Expand Down Expand Up @@ -27,7 +27,7 @@ export function createEditMenu(
click: () =>
injection.sender.send({
id: uuid.v4(),
type: ServerMessageType.Undo,
type: MessageType.Undo,
payload: undefined
})
},
Expand All @@ -39,7 +39,7 @@ export function createEditMenu(
injection.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.Redo
type: MessageType.Redo
})
},
{
Expand All @@ -53,7 +53,7 @@ export function createEditMenu(
injection.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.Cut
type: MessageType.Cut
});
Electron.Menu.sendActionToFirstResponder('cut:');
}
Expand All @@ -66,7 +66,7 @@ export function createEditMenu(
injection.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.Copy
type: MessageType.Copy
});
Electron.Menu.sendActionToFirstResponder('copy:');
}
Expand All @@ -79,7 +79,7 @@ export function createEditMenu(
injection.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.Paste
type: MessageType.Paste
});
Electron.Menu.sendActionToFirstResponder('paste:');
}
Expand All @@ -95,7 +95,7 @@ export function createEditMenu(
injection.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.Duplicate
type: MessageType.Duplicate
});
}
},
Expand All @@ -118,7 +118,7 @@ export function createEditMenu(
injection.sender.send({
id: uuid.v4(),
payload: undefined,
type: ServerMessageType.Delete
type: MessageType.Delete
});
Electron.Menu.sendActionToFirstResponder('delete:');
}
Expand Down
Loading

0 comments on commit f78b70e

Please sign in to comment.