Skip to content

Commit 3c71759

Browse files
committed
update
1 parent 76eaad1 commit 3c71759

File tree

238 files changed

+17242
-12816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+17242
-12816
lines changed

.eslintrc.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"overrides": [
12+
{
13+
"env": {
14+
"node": true
15+
},
16+
"files": [
17+
".eslintrc.{js,cjs}"
18+
],
19+
"parserOptions": {
20+
"sourceType": "script"
21+
}
22+
}
23+
],
24+
"parser": "@typescript-eslint/parser",
25+
"parserOptions": {
26+
"ecmaVersion": "latest"
27+
},
28+
"plugins": [
29+
"@typescript-eslint"
30+
],
31+
"rules": {
32+
"@typescript-eslint/no-explicit-any": "off",
33+
"indent": [
34+
"error",
35+
4
36+
],
37+
"linebreak-style": [
38+
"error",
39+
"unix"
40+
],
41+
"quotes": [
42+
"error",
43+
"double"
44+
],
45+
"semi": [
46+
"error",
47+
"always"
48+
]
49+
}
50+
};

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/** linguist-vendored
2+
*.js linguist-vendored

.github/workflows/node.js.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [20.x, 21.x, 22.x]
19+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'npm'
28+
- run: npm ci
29+
- run: npm run build --if-present
30+
- run: npm test

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/.idea
2-
/*.sublime-project
3-
/*.sublime-workspace
4-
/build/user.properties
1+
.idea
2+
node_modules
3+
.DS_Store

LICENSE

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
* PureMVC Standard Framework for TypeScript - Copyright © 2012 Frederic Saunier
2-
* PureMVC Framework - Copyright © 2006-2012 Futurescale, Inc.
3-
* All rights reserved.
4-
5-
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6-
7-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9-
* Neither the name of Futurescale, Inc., PureMVC.org, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10-
11-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2024, Saad Shams <[email protected]>
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+19-36
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
1-
## [PureMVC](http://puremvc.github.com/) TypeScript Standard Framework
2-
PureMVC is a lightweight framework for creating applications based upon the classic [Model-View-Controller](http://en.wikipedia.org/wiki/Model-view-controller) design meta-pattern. This is a TypeScript port of the [AS3 reference implementation of the Standard Version](https://github.com/PureMVC/puremvc-as3-standard-framework/wiki). It does not support modular programming since it uses [Singleton](http://en.wikipedia.org/wiki/Singleton_pattern)s as Core actors rather than the [Multiton](http://en.wikipedia.org/wiki/Multiton)s used in the [MultiCore Version](https://github.com/PureMVC/puremvc-typescript-multicore-framework/wiki/).
1+
## [PureMVC](http://puremvc.org/) TypeScript Standard Framework [![Node.js CI](https://github.com/PureMVC/puremvc-typescript-standard-framework/actions/workflows/node.js.yml/badge.svg)](https://github.com/PureMVC/puremvc-typescript-standard-framework/actions/workflows/node.js.yml)
32

4-
Unit Tests are included in this repository.
3+
PureMVC is a lightweight framework for creating applications based upon the classic [Model-View-Controller](http://en.wikipedia.org/wiki/Model-view-controller) design meta-pattern. It does not support [modular programming](http://en.wikipedia.org/wiki/Modular_programming) since it uses [Singleton](http://en.wikipedia.org/wiki/Singleton_pattern)s as Core actors rather than the [Multiton](http://en.wikipedia.org/wiki/Multiton)s used in the [MultiCore](https://github.com/PureMVC/puremvc-typescript-multicore-framework/wiki/) Version.
54

6-
* [Discussion](http://forums.puremvc.org/index.php?board=112.0)
7-
* [Live Unit Test Runner](http://puremvc.org/pages/demos/TS/PureMVC_TS_Standard_UnitTests/)
8-
* [Demo: Employee Admin](https://github.com/PureMVC/puremvc-typescript-demo-employeeadmin/wiki)
9-
10-
## Status
11-
Production- [Version 1.0](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/VERSION)
5+
* [API Docs](https://puremvc.org/pages/docs/TypeScript/standard/)
6+
* [Legacy Implementation](https://github.com/PureMVC/puremvc-typescript-standard-framework/tree/1.0.1)
127

138
## Platforms / Technologies
14-
* [TypeScript](http://www.typescriptlang.org/)
15-
* [YUI Test](https://github.com/yui/yuitest)
16-
* [YUI Compressor](http://developer.yahoo.com/yui/compressor/)
17-
* [YUIAnt](http://www.ubik-ingenierie.com/miscellanous/YUIAnt/)
18-
* [Ant](http://ant.apache.org/)
19-
20-
## Usage
21-
22-
As this port depends on the TypeScript language you may want to start by reading [TypeScript getting started guide](http://www.typescriptlang.org/).
23-
24-
Unit Test can be run live in the browser using included HTML file [test.html](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/test-minified.html)
9+
* [TypeScript](https://en.wikipedia.org/wiki/TypeScript)
10+
* [JavaScript](https://en.wikipedia.org/wiki/JavaScript)
11+
* [ECMAScript](https://en.wikipedia.org/wiki/ECMAScript)
12+
* [CommonJS](https://en.wikipedia.org/wiki/CommonJS)
13+
* [Node.js](https://en.wikipedia.org/wiki/Node.js)
14+
* [React](https://en.wikipedia.org/wiki/React_(JavaScript_library))
15+
* [React Native](https://en.wikipedia.org/wiki/React_Native)
2516

26-
## Build
27-
28-
To build the project you'll need to download and install :
29-
* [TypeScript compiler](http://www.typescriptlang.org/#Download)
30-
* [Ant](http://ant.apache.org/)
31-
* [JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html/) (Ant need a JDK not a JRE, also don't forget to change environment var JAVA_HOME to the JDK path).
32-
33-
1. Rename the file [user.properties.sample](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/user.properties.sample) to **user.properties**
34-
2. Edit the file and replace **MY_TYPESCRIPT_COMPILER_PATH** by the real TypeScript compiler full
35-
system path. e.g. on windows: `<code>`typescript.compiler.path = C:/Documents and Settings/{USER NAME HERE}/Application Data/npm/tsc.cmd
36-
3. Use your favorite editor to run Ant or simply type `<code>`ant puremvc-typescript-standard-framework/build
17+
## Status
18+
Production - [Version 2.0.0](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/VERSION)
3719

3820
## License
39-
* PureMVC TypeScript Standard Framework - Copyright © 2012 Frederic Saunier
40-
* PureMVC - Copyright © 2006-2012 Futurescale, Inc.
21+
* PureMVC Standard Framework for TypeScript - Copyright © 2024 [Saad Shams](https://www.linkedin.com/in/muizz)
22+
* PureMVC - Copyright © 2024 [Futurescale, Inc.](http://futurescale.com/)
4123
* All rights reserved.
4224

4325
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4426

45-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
46-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
47-
* Neither the name of Futurescale, Inc., PureMVC.org, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
27+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
28+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
29+
* Neither the name of Futurescale, Inc., PureMVC.org, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
4830

4931
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+

VERSION

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
PureMVC Standard Framework for TypeScript
2-
----------------------------------------------------------------------------------------------------
3-
Release Date: 11/10/2012
4-
Platform: TypeScript
5-
Version: 1
6-
Revision: 0
7-
Author: Frederic Saunier <[email protected]>
8-
----------------------------------------------------------------------------------------------------
9-
10-
1.0 - First official PureMVC TypeScript Standard port.
11-
12-
This port, is inspired originally from PureMVC Standard Framework for AS3 port by Cliff Hall but was
13-
converted both from PureMVC AS3 Standard port and PureMVC JavaScript Standard for Objs Unit Tests.
14-
15-
Will probably stay tagged as development while TypeScript language specification is not finalized,
16-
but remember that any TypeScript PureMVC project will output ready for production JavaScript.
1+
PureMVC Standard Framework for TypeScript
2+
--------------------------------------------------------------------------
3+
Release Date: 11/03/24
4+
Platform: TypeScript
5+
Version: 2
6+
Revision: 0
7+
Minor: 0
8+
Authors: Saad Shams <[email protected]>
9+
--------------------------------------------------------------------------
10+
2.0.0 - Brand new implementation of ported code, equivalent to AS3 Standard Version 2.0.4.

bin/cjs/core/Controller.js

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
"use strict";
2+
//
3+
// Controller.ts
4+
// PureMVC TypeScript Multicore
5+
//
6+
// Copyright(c) 2024 Saad Shams <[email protected]>
7+
// Your reuse is governed by the BSD-3-Clause License
8+
//
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
exports.Controller = void 0;
11+
const View_1 = require("./View");
12+
const Observer_1 = require("../patterns/observer/Observer");
13+
/**
14+
* A Singleton `Controller` implementation.
15+
*
16+
* In PureMVC, the `Controller` class follows the
17+
* 'Command and Controller' strategy, and assumes these
18+
* responsibilities:
19+
*
20+
*
21+
* - Remembering which `Command`s
22+
* are intended to handle which `Notifications`.
23+
* - Registering itself as an `Observer` with
24+
* the `View` for each `Notification`
25+
* that it has a `Command` mapping for.
26+
* - Creating a new instance of the proper `Command`
27+
* to handle a given `Notification` when notified by the `View`.
28+
* - Calling the `Command`'s `execute`
29+
* method, passing in the `Notification`.
30+
*
31+
*
32+
* Your application must register `Commands` with the
33+
* Controller.
34+
*
35+
* The simplest way is to subclass `Facade`,
36+
* and use its `initializeController` method to add your
37+
* registrations.
38+
*
39+
* @see {@link View}
40+
* @see {@link Observer}
41+
* @see {@link Notification}
42+
* @see {@link SimpleCommand}
43+
* @see {@link MacroCommand}
44+
*
45+
* @class Controller
46+
*/
47+
class Controller {
48+
/**
49+
* Constructor.
50+
*
51+
* This `Controller` implementation is a Singleton,
52+
* so you should not call the constructor
53+
* directly, but instead call the static Singleton Factory method,
54+
* `Controller.getInstance()`
55+
*
56+
* @throws {Error} Error if instance for this Singleton has already been constructed
57+
*/
58+
constructor() {
59+
if (Controller.instance != null) {
60+
throw Error(Controller.SINGLETON_MSG);
61+
}
62+
Controller.instance = this;
63+
this.commandMap = {};
64+
this.initializeController();
65+
}
66+
/**
67+
* Initialize the Singleton `Controller` instance.
68+
*
69+
* Called automatically by the constructor.
70+
*
71+
* Note that if you are using a subclass of `View`
72+
* in your application, you should <i>also</i> subclass `Controller`
73+
* and override the `initializeController` method in the
74+
* following way:
75+
*
76+
* ```ts
77+
* // ensure that the Controller is talking to my View implementation
78+
* initializeController() {
79+
* this.view = MyView.getInstance(() => new View());
80+
* }
81+
* ```
82+
* @returns {void}
83+
*/
84+
initializeController() {
85+
this.view = View_1.View.getInstance(() => new View_1.View());
86+
}
87+
/**
88+
* `Controller` Singleton Factory method.
89+
*
90+
* @param {() => IController} factory - A factory function that creates a new instance of the controller if one does not already exist.
91+
* @returns {IController} the Singleton instance of `Controller`.
92+
*/
93+
static getInstance(factory) {
94+
if (Controller.instance == null)
95+
Controller.instance = factory();
96+
return Controller.instance;
97+
}
98+
/**
99+
* Register a particular `Command` class as the handler
100+
* for a particular `Notification`.
101+
*
102+
* If an `Command` has already been registered to
103+
* handle `Notification`s with this name, it is no longer
104+
* used, the new `Command` is used instead.
105+
*
106+
* The Observer for the new Command is only created if this the
107+
* first time a Command has been registered for this Notification name.
108+
*
109+
* @param {string} notificationName - The name of the notification to associate with the command.
110+
* @param {() => ICommand} factory - A factory function that returns an instance of the command.
111+
* @returns {void}
112+
*/
113+
registerCommand(notificationName, factory) {
114+
var _a;
115+
if (this.commandMap[notificationName] == null) {
116+
(_a = this.view) === null || _a === void 0 ? void 0 : _a.registerObserver(notificationName, new Observer_1.Observer(this.executeCommand, this));
117+
}
118+
this.commandMap[notificationName] = factory;
119+
}
120+
/**
121+
* If a `Command` has previously been registered
122+
* to handle the given `Notification`, then it is executed.
123+
*
124+
* @param {INotification} notification - The notification containing the data or command details needed for execution.
125+
* @returns {void}
126+
*/
127+
executeCommand(notification) {
128+
const factory = this.commandMap[notification.name];
129+
if (factory == null)
130+
return;
131+
const command = factory();
132+
command.execute(notification);
133+
}
134+
/**
135+
* Check if a Command is registered for a given Notification
136+
*
137+
* @param {string} notificationName - The name of the notification to check for a registered command.
138+
* @returns {boolean} `true` if a command is registered for the specified notification name; otherwise, `false`.
139+
*/
140+
hasCommand(notificationName) {
141+
return this.commandMap[notificationName] != null;
142+
}
143+
/**
144+
* Remove a previously registered `Command` to `Notification` mapping.
145+
*
146+
* @param {string} notificationName - The name of the notification for which the associated command should be removed.
147+
* @returns {void}
148+
*/
149+
removeCommand(notificationName) {
150+
var _a;
151+
// if the Command is registered...
152+
if (this.hasCommand(notificationName)) {
153+
// remove the observer
154+
(_a = this.view) === null || _a === void 0 ? void 0 : _a.removeObserver(notificationName, this);
155+
// remove the command
156+
delete this.commandMap[notificationName];
157+
}
158+
}
159+
}
160+
exports.Controller = Controller;
161+
/** Message Constants
162+
* @type {string} */
163+
Controller.SINGLETON_MSG = "Controller Singleton already constructed!";

0 commit comments

Comments
 (0)