forked from jonopus/puremvc-typescript-singlecore
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
238 changed files
with
17,242 additions
and
12,816 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,50 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"overrides": [ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"files": [ | ||
".eslintrc.{js,cjs}" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script" | ||
} | ||
} | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"indent": [ | ||
"error", | ||
4 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
}; |
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,2 @@ | ||
bin/** linguist-vendored | ||
*.js linguist-vendored |
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,30 @@ | ||
# 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 | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x, 21.x, 22.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/.idea | ||
/*.sublime-project | ||
/*.sublime-workspace | ||
/build/user.properties | ||
.idea | ||
node_modules | ||
.DS_Store |
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 |
---|---|---|
@@ -1,11 +1,28 @@ | ||
* PureMVC Standard Framework for TypeScript - Copyright © 2012 Frederic Saunier | ||
* PureMVC Framework - Copyright © 2006-2012 Futurescale, Inc. | ||
* All rights reserved. | ||
|
||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* 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. | ||
* 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. | ||
|
||
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. | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2024, Saad Shams <saad.shams@puremvc.org> | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. 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. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
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. |
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 |
---|---|---|
@@ -1,49 +1,32 @@ | ||
## [PureMVC](http://puremvc.github.com/) TypeScript Standard Framework | ||
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/). | ||
## [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) | ||
|
||
Unit Tests are included in this repository. | ||
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. | ||
|
||
* [Discussion](http://forums.puremvc.org/index.php?board=112.0) | ||
* [Live Unit Test Runner](http://puremvc.org/pages/demos/TS/PureMVC_TS_Standard_UnitTests/) | ||
* [Demo: Employee Admin](https://github.com/PureMVC/puremvc-typescript-demo-employeeadmin/wiki) | ||
|
||
## Status | ||
Production- [Version 1.0](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/VERSION) | ||
* [API Docs](https://puremvc.org/pages/docs/TypeScript/standard/) | ||
* [Legacy Implementation](https://github.com/PureMVC/puremvc-typescript-standard-framework/tree/1.0.1) | ||
|
||
## Platforms / Technologies | ||
* [TypeScript](http://www.typescriptlang.org/) | ||
* [YUI Test](https://github.com/yui/yuitest) | ||
* [YUI Compressor](http://developer.yahoo.com/yui/compressor/) | ||
* [YUIAnt](http://www.ubik-ingenierie.com/miscellanous/YUIAnt/) | ||
* [Ant](http://ant.apache.org/) | ||
|
||
## Usage | ||
|
||
As this port depends on the TypeScript language you may want to start by reading [TypeScript getting started guide](http://www.typescriptlang.org/). | ||
|
||
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) | ||
* [TypeScript](https://en.wikipedia.org/wiki/TypeScript) | ||
* [JavaScript](https://en.wikipedia.org/wiki/JavaScript) | ||
* [ECMAScript](https://en.wikipedia.org/wiki/ECMAScript) | ||
* [CommonJS](https://en.wikipedia.org/wiki/CommonJS) | ||
* [Node.js](https://en.wikipedia.org/wiki/Node.js) | ||
* [React](https://en.wikipedia.org/wiki/React_(JavaScript_library)) | ||
* [React Native](https://en.wikipedia.org/wiki/React_Native) | ||
|
||
## Build | ||
|
||
To build the project you'll need to download and install : | ||
* [TypeScript compiler](http://www.typescriptlang.org/#Download) | ||
* [Ant](http://ant.apache.org/) | ||
* [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). | ||
|
||
1. Rename the file [user.properties.sample](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/user.properties.sample) to **user.properties** | ||
2. Edit the file and replace **MY_TYPESCRIPT_COMPILER_PATH** by the real TypeScript compiler full | ||
system path. e.g. on windows: `<code>`typescript.compiler.path = C:/Documents and Settings/{USER NAME HERE}/Application Data/npm/tsc.cmd | ||
3. Use your favorite editor to run Ant or simply type `<code>`ant puremvc-typescript-standard-framework/build | ||
## Status | ||
Production - [Version 2.0.0](https://github.com/PureMVC/puremvc-typescript-standard-framework/blob/master/VERSION) | ||
|
||
## License | ||
* PureMVC TypeScript Standard Framework - Copyright © 2012 Frederic Saunier | ||
* PureMVC - Copyright © 2006-2012 Futurescale, Inc. | ||
* PureMVC Standard Framework for TypeScript - Copyright © 2024 [Saad Shams](https://www.linkedin.com/in/muizz) | ||
* PureMVC - Copyright © 2024 [Futurescale, Inc.](http://futurescale.com/) | ||
* All rights reserved. | ||
|
||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* 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. | ||
* 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. | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* 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. | ||
* 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. | ||
|
||
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. | ||
|
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 |
---|---|---|
@@ -1,16 +1,10 @@ | ||
PureMVC Standard Framework for TypeScript | ||
---------------------------------------------------------------------------------------------------- | ||
Release Date: 11/10/2012 | ||
Platform: TypeScript | ||
Version: 1 | ||
Revision: 0 | ||
Author: Frederic Saunier <frederic.saunier@puremvc.org> | ||
---------------------------------------------------------------------------------------------------- | ||
|
||
1.0 - First official PureMVC TypeScript Standard port. | ||
|
||
This port, is inspired originally from PureMVC Standard Framework for AS3 port by Cliff Hall but was | ||
converted both from PureMVC AS3 Standard port and PureMVC JavaScript Standard for Objs Unit Tests. | ||
|
||
Will probably stay tagged as development while TypeScript language specification is not finalized, | ||
but remember that any TypeScript PureMVC project will output ready for production JavaScript. | ||
PureMVC Standard Framework for TypeScript | ||
-------------------------------------------------------------------------- | ||
Release Date: 11/03/24 | ||
Platform: TypeScript | ||
Version: 2 | ||
Revision: 0 | ||
Minor: 0 | ||
Authors: Saad Shams <saad.shams@puremvc.org> | ||
-------------------------------------------------------------------------- | ||
2.0.0 - Brand new implementation of ported code, equivalent to AS3 Standard Version 2.0.4. |
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,163 @@ | ||
"use strict"; | ||
// | ||
// Controller.ts | ||
// PureMVC TypeScript Multicore | ||
// | ||
// Copyright(c) 2024 Saad Shams <saad.shams@puremvc.org> | ||
// Your reuse is governed by the BSD-3-Clause License | ||
// | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Controller = void 0; | ||
const View_1 = require("./View"); | ||
const Observer_1 = require("../patterns/observer/Observer"); | ||
/** | ||
* A Singleton `Controller` implementation. | ||
* | ||
* In PureMVC, the `Controller` class follows the | ||
* 'Command and Controller' strategy, and assumes these | ||
* responsibilities: | ||
* | ||
* | ||
* - Remembering which `Command`s | ||
* are intended to handle which `Notifications`. | ||
* - Registering itself as an `Observer` with | ||
* the `View` for each `Notification` | ||
* that it has a `Command` mapping for. | ||
* - Creating a new instance of the proper `Command` | ||
* to handle a given `Notification` when notified by the `View`. | ||
* - Calling the `Command`'s `execute` | ||
* method, passing in the `Notification`. | ||
* | ||
* | ||
* Your application must register `Commands` with the | ||
* Controller. | ||
* | ||
* The simplest way is to subclass `Facade`, | ||
* and use its `initializeController` method to add your | ||
* registrations. | ||
* | ||
* @see {@link View} | ||
* @see {@link Observer} | ||
* @see {@link Notification} | ||
* @see {@link SimpleCommand} | ||
* @see {@link MacroCommand} | ||
* | ||
* @class Controller | ||
*/ | ||
class Controller { | ||
/** | ||
* Constructor. | ||
* | ||
* This `Controller` implementation is a Singleton, | ||
* so you should not call the constructor | ||
* directly, but instead call the static Singleton Factory method, | ||
* `Controller.getInstance()` | ||
* | ||
* @throws {Error} Error if instance for this Singleton has already been constructed | ||
*/ | ||
constructor() { | ||
if (Controller.instance != null) { | ||
throw Error(Controller.SINGLETON_MSG); | ||
} | ||
Controller.instance = this; | ||
this.commandMap = {}; | ||
this.initializeController(); | ||
} | ||
/** | ||
* Initialize the Singleton `Controller` instance. | ||
* | ||
* Called automatically by the constructor. | ||
* | ||
* Note that if you are using a subclass of `View` | ||
* in your application, you should <i>also</i> subclass `Controller` | ||
* and override the `initializeController` method in the | ||
* following way: | ||
* | ||
* ```ts | ||
* // ensure that the Controller is talking to my View implementation | ||
* initializeController() { | ||
* this.view = MyView.getInstance(() => new View()); | ||
* } | ||
* ``` | ||
* @returns {void} | ||
*/ | ||
initializeController() { | ||
this.view = View_1.View.getInstance(() => new View_1.View()); | ||
} | ||
/** | ||
* `Controller` Singleton Factory method. | ||
* | ||
* @param {() => IController} factory - A factory function that creates a new instance of the controller if one does not already exist. | ||
* @returns {IController} the Singleton instance of `Controller`. | ||
*/ | ||
static getInstance(factory) { | ||
if (Controller.instance == null) | ||
Controller.instance = factory(); | ||
return Controller.instance; | ||
} | ||
/** | ||
* Register a particular `Command` class as the handler | ||
* for a particular `Notification`. | ||
* | ||
* If an `Command` has already been registered to | ||
* handle `Notification`s with this name, it is no longer | ||
* used, the new `Command` is used instead. | ||
* | ||
* The Observer for the new Command is only created if this the | ||
* first time a Command has been registered for this Notification name. | ||
* | ||
* @param {string} notificationName - The name of the notification to associate with the command. | ||
* @param {() => ICommand} factory - A factory function that returns an instance of the command. | ||
* @returns {void} | ||
*/ | ||
registerCommand(notificationName, factory) { | ||
var _a; | ||
if (this.commandMap[notificationName] == null) { | ||
(_a = this.view) === null || _a === void 0 ? void 0 : _a.registerObserver(notificationName, new Observer_1.Observer(this.executeCommand, this)); | ||
} | ||
this.commandMap[notificationName] = factory; | ||
} | ||
/** | ||
* If a `Command` has previously been registered | ||
* to handle the given `Notification`, then it is executed. | ||
* | ||
* @param {INotification} notification - The notification containing the data or command details needed for execution. | ||
* @returns {void} | ||
*/ | ||
executeCommand(notification) { | ||
const factory = this.commandMap[notification.name]; | ||
if (factory == null) | ||
return; | ||
const command = factory(); | ||
command.execute(notification); | ||
} | ||
/** | ||
* Check if a Command is registered for a given Notification | ||
* | ||
* @param {string} notificationName - The name of the notification to check for a registered command. | ||
* @returns {boolean} `true` if a command is registered for the specified notification name; otherwise, `false`. | ||
*/ | ||
hasCommand(notificationName) { | ||
return this.commandMap[notificationName] != null; | ||
} | ||
/** | ||
* Remove a previously registered `Command` to `Notification` mapping. | ||
* | ||
* @param {string} notificationName - The name of the notification for which the associated command should be removed. | ||
* @returns {void} | ||
*/ | ||
removeCommand(notificationName) { | ||
var _a; | ||
// if the Command is registered... | ||
if (this.hasCommand(notificationName)) { | ||
// remove the observer | ||
(_a = this.view) === null || _a === void 0 ? void 0 : _a.removeObserver(notificationName, this); | ||
// remove the command | ||
delete this.commandMap[notificationName]; | ||
} | ||
} | ||
} | ||
exports.Controller = Controller; | ||
/** Message Constants | ||
* @type {string} */ | ||
Controller.SINGLETON_MSG = "Controller Singleton already constructed!"; |
Oops, something went wrong.