Skip to content

Commit

Permalink
refactor: add form scene lifecycle messages to MainScene #19
Browse files Browse the repository at this point in the history
  • Loading branch information
metasansana committed Apr 2, 2022
1 parent 0c679e1 commit eccc4e7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
16 changes: 11 additions & 5 deletions lib/app/scene/main.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Future } from '@quenk/noni/lib/control/monad/future';
import { Case } from '@quenk/potoo/lib/actor/resident/case';
import { System } from '@quenk/potoo/lib/actor/system';
import { Resume, Suspend, SuspendListener } from '../service/director';
import { Pop, Push, Show } from '../service/display';
import { BaseAppScene } from './';
import { FormAborted, FormSaved, FormListener } from './form';
/**
* MainSceneMessage type.
*/
export declare type MainSceneMessage<M> = Suspend | Show | Push | Pop | M;
export declare type MainSceneMessage<M> = Suspend | Show | Push | Pop | FormAborted | FormSaved | M;
/**
* MainScene is an actor used to provide one of the primary activity views of an
* application.
Expand All @@ -15,20 +17,24 @@ export declare type MainSceneMessage<M> = Suspend | Show | Push | Pop | M;
* which can spawn them on demand in response to the app's "route" changing.
*
* The [[Resume]] parameter serves as proof that the MainScene is allowed by the
* Director to send content to the user (by sending a [[Show]] to the director.
* Director to send content to the user (by sending a [[Show]] message to the
* director).
*
* When the Director decides it's time for another actor to be given that right,
* the MainScene is terminiated but is given a chance to clean up via a
* [[Suspend]].
* the MainScene is terminiated but will receive a [[Suspend]] message which can
* be used to clean up.
*
* MainScene is intentionally basic to allow for the flexibility needed when
* composing the complex main activities of a routed application. However, to
* make working with [[FormScene]]s and [[Dialog]]s easier, it contains Case
* classes for redirecting content received to the Director.
*/
export declare abstract class MainScene<T, M> extends BaseAppScene<MainSceneMessage<M>> implements SuspendListener {
export declare abstract class MainScene<T, M> extends BaseAppScene<MainSceneMessage<M>> implements SuspendListener, FormListener {
system: System;
resume: Resume<T>;
constructor(system: System, resume: Resume<T>);
afterFormSaved(_: FormSaved): void | Future<void>;
afterFormAborted(_: FormAborted): void | Future<void>;
get display(): string;
receive(): Case<MainSceneMessage<M>>[];
beforeSuspended(_: Suspend): void;
Expand Down
14 changes: 10 additions & 4 deletions lib/app/scene/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/app/scene/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions lib/app/scene/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Future } from '@quenk/noni/lib/control/monad/future';
import { Case } from '@quenk/potoo/lib/actor/resident/case';
import { System } from '@quenk/potoo/lib/actor/system';

Expand All @@ -10,6 +11,7 @@ import {
} from '../service/director';
import { Pop, Push, Show, Close } from '../service/display';
import { BaseAppScene } from './';
import { FormAborted, FormSaved, FormListener, FormAbortedCase, FormSavedCase } from './form';

/**
* MainSceneMessage type.
Expand All @@ -19,6 +21,8 @@ export type MainSceneMessage<M>
| Show
| Push
| Pop
| FormAborted
| FormSaved
| M
;

Expand All @@ -30,10 +34,12 @@ export type MainSceneMessage<M>
* which can spawn them on demand in response to the app's "route" changing.
*
* The [[Resume]] parameter serves as proof that the MainScene is allowed by the
* Director to send content to the user (by sending a [[Show]] to the director.
* Director to send content to the user (by sending a [[Show]] message to the
* director).
*
* When the Director decides it's time for another actor to be given that right,
* the MainScene is terminiated but is given a chance to clean up via a
* [[Suspend]].
* the MainScene is terminiated but will receive a [[Suspend]] message which can
* be used to clean up.
*
* MainScene is intentionally basic to allow for the flexibility needed when
* composing the complex main activities of a routed application. However, to
Expand All @@ -44,14 +50,19 @@ export abstract class MainScene<T, M>
extends
BaseAppScene<MainSceneMessage<M>>
implements
SuspendListener {
SuspendListener,
FormListener {

constructor(public system: System, public resume: Resume<T>) {

super(system);

}

afterFormSaved(_: FormSaved): void | Future<void> { }

afterFormAborted(_: FormAborted): void | Future<void> { }

get display() {

return this.resume.director;
Expand All @@ -64,7 +75,9 @@ export abstract class MainScene<T, M>

new SuspendCase(this, this.resume.director),

new Case(Show, (msg: Show) => void this.tell(this.display, msg)),
new FormAbortedCase(this),

new FormSavedCase(this),

new Case(Push, (msg: Push) => void this.tell(this.display, msg)),

Expand Down
23 changes: 18 additions & 5 deletions src/app/scene/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Future } from '@quenk/noni/lib/control/monad/future';
import { Case } from '@quenk/potoo/lib/actor/resident/case';
import { System } from '@quenk/potoo/lib/actor/system';

Expand All @@ -10,6 +11,7 @@ import {
} from '../service/director';
import { Pop, Push, Show, Close } from '../service/display';
import { BaseAppScene } from './';
import { FormAborted, FormSaved, FormListener, FormAbortedCase, FormSavedCase } from './form';

/**
* MainSceneMessage type.
Expand All @@ -19,6 +21,8 @@ export type MainSceneMessage<M>
| Show
| Push
| Pop
| FormAborted
| FormSaved
| M
;

Expand All @@ -30,10 +34,12 @@ export type MainSceneMessage<M>
* which can spawn them on demand in response to the app's "route" changing.
*
* The [[Resume]] parameter serves as proof that the MainScene is allowed by the
* Director to send content to the user (by sending a [[Show]] to the director.
* Director to send content to the user (by sending a [[Show]] message to the
* director).
*
* When the Director decides it's time for another actor to be given that right,
* the MainScene is terminiated but is given a chance to clean up via a
* [[Suspend]].
* the MainScene is terminiated but will receive a [[Suspend]] message which can
* be used to clean up.
*
* MainScene is intentionally basic to allow for the flexibility needed when
* composing the complex main activities of a routed application. However, to
Expand All @@ -44,14 +50,19 @@ export abstract class MainScene<T, M>
extends
BaseAppScene<MainSceneMessage<M>>
implements
SuspendListener {
SuspendListener,
FormListener {

constructor(public system: System, public resume: Resume<T>) {

super(system);

}

afterFormSaved(_: FormSaved): void | Future<void> { }

afterFormAborted(_: FormAborted): void | Future<void> { }

get display() {

return this.resume.director;
Expand All @@ -64,7 +75,9 @@ export abstract class MainScene<T, M>

new SuspendCase(this, this.resume.director),

new Case(Show, (msg: Show) => void this.tell(this.display, msg)),
new FormAbortedCase(this),

new FormSavedCase(this),

new Case(Push, (msg: Push) => void this.tell(this.display, msg)),

Expand Down

0 comments on commit eccc4e7

Please sign in to comment.