-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Events] Implement basic Action entity (fixes #13).
- Loading branch information
Showing
10 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export interface IAction { | ||
name: string; | ||
type: string; | ||
|
||
perform(): Promise<boolean>; | ||
} | ||
|
||
export class Action implements IAction { | ||
private _name: string; | ||
private _type: string; | ||
|
||
constructor(name: string, type: string) { | ||
this._name = name; | ||
this._type = type; | ||
} | ||
|
||
get name() { | ||
return this._name; | ||
} | ||
|
||
get type() { | ||
return this._type; | ||
} | ||
|
||
perform() { | ||
return Promise.reject<boolean>(new Error('Not Implemented!')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Action } from 'core/actions/action'; | ||
import { IMessage } from 'core/events/message'; | ||
import { IMessageChannel } from 'core/events/message-channel'; | ||
|
||
export class BroadcastAction extends Action { | ||
private _channel: IMessageChannel; | ||
private _message: IMessage; | ||
|
||
constructor(channel: IMessageChannel, message: IMessage) { | ||
super('Broadcast', 'broadcast-action'); | ||
|
||
this._channel = channel; | ||
this._message = message; | ||
} | ||
|
||
get channel() { | ||
return this._channel; | ||
} | ||
|
||
get message() { | ||
return this._message; | ||
} | ||
|
||
perform() { | ||
try { | ||
this._channel.send(this._message); | ||
return Promise.resolve(true); | ||
} catch(e) { | ||
return Promise.reject<boolean>(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Action } from 'core/actions/action'; | ||
import { IProperty } from 'core/property'; | ||
|
||
export class ChangePropertyAction<TPropertyValue> extends Action { | ||
private _property: IProperty<TPropertyValue>; | ||
private _value: TPropertyValue; | ||
|
||
constructor(property: IProperty<TPropertyValue>, value: TPropertyValue) { | ||
super('Change Property', 'change-property-action'); | ||
|
||
this._property = property; | ||
this._value = value; | ||
} | ||
|
||
get property() { | ||
return this._property; | ||
} | ||
|
||
get value() { | ||
return this._value; | ||
} | ||
|
||
perform() { | ||
try { | ||
this._property.setValue(this._value); | ||
return Promise.resolve(true); | ||
} catch(e) { | ||
return Promise.reject<boolean>(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters