From 6c85d0c061fe80e70f694b66cef7b997c0244817 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Fri, 4 Aug 2023 19:59:34 +0300 Subject: [PATCH 01/21] Linter rules config added --- analysis_options.yaml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..48f2f69 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,31 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # non_constant_identifier_names: false + # constant_identifier_names: false + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options From 908a7f52060ffd22e949d544ec7e2f12af968db4 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sat, 5 Aug 2023 12:29:35 +0300 Subject: [PATCH 02/21] Conform framework to the Dart 3 version. Make tests pass. --- .gitignore | 835 +++++++++++++++++++- example/Framework_Verify.dart | 62 +- example/Framework_Verify.html | 3 +- lib/src/core/Controller.dart | 84 +- lib/src/core/Model.dart | 71 +- lib/src/core/View.dart | 183 ++--- lib/src/interfaces/ICommand.dart | 5 +- lib/src/interfaces/IController.dart | 13 +- lib/src/interfaces/IFacade.dart | 295 ++++--- lib/src/interfaces/IMediator.dart | 22 +- lib/src/interfaces/IModel.dart | 25 +- lib/src/interfaces/INotification.dart | 92 +-- lib/src/interfaces/INotifier.dart | 11 +- lib/src/interfaces/IObserver.dart | 95 +-- lib/src/interfaces/IProxy.dart | 37 +- lib/src/interfaces/IView.dart | 20 +- lib/src/patterns/command/MacroCommand.dart | 30 +- lib/src/patterns/command/SimpleCommand.dart | 9 +- lib/src/patterns/facade/Facade.dart | 175 ++-- lib/src/patterns/mediator/Mediator.dart | 26 +- lib/src/patterns/observer/Notification.dart | 129 ++- lib/src/patterns/observer/Notifier.dart | 88 +-- lib/src/patterns/observer/Observer.dart | 44 +- lib/src/patterns/proxy/Proxy.dart | 51 +- pubspec.lock | 557 +++++++++++++ pubspec.yaml | 9 +- test/Test_Controller.dart | 98 +-- test/Test_Facade.dart | 302 ++++--- test/Test_MacroCommand.dart | 55 +- test/Test_Mediator.dart | 39 +- test/Test_Model.dart | 74 +- test/Test_Notification.dart | 42 +- test/Test_Observer.dart | 68 +- test/Test_Proxy.dart | 42 +- test/Test_SimpleCommand.dart | 45 +- test/Test_View.dart | 137 ++-- test/Unit_Tests.dart | 51 +- 37 files changed, 2526 insertions(+), 1398 deletions(-) create mode 100644 pubspec.lock diff --git a/.gitignore b/.gitignore index bfacf56..26f654f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,831 @@ -pubspec.lock -*.dart.js* -*.dart.js.deps* -*.dart.precompiled.js \ No newline at end of file +### ------------------------- Flutter.gitignore ------------------------ ### + +# Miscellaneous +*.class +#*.lock +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.classpath +.project +.settings/ +.vscode/ + +# Flutter repo-specific +/bin/cache/ +/bin/internal/bootstrap.bat +/bin/internal/bootstrap.sh +/bin/mingit/ +/dev/benchmarks/mega_gallery/ +/dev/bots/.recipe_deps +/dev/bots/android_tools/ +/dev/devicelab/ABresults*.json +/dev/docs/doc/ +/dev/docs/flutter.docs.zip +/dev/docs/lib/ +/dev/docs/pubspec.yaml +/dev/integration_tests/**/xcuserdata +/dev/integration_tests/**/Pods +/packages/flutter/coverage/ +version +analysis_benchmark.json + +# packages file containing multi-root paths +.packages.generated + +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +**/generated_plugin_registrant.dart +.packages +.pub-cache/ +.pub/ +build/ +flutter_*.png +linked_*.ds +unlinked.ds +unlinked_spec.ds + +# Android related +**/android/**/gradle-wrapper.jar +.gradle/ +**/android/captures/ +**/android/gradlew +**/android/gradlew.bat +**/android/local.properties +**/android/**/GeneratedPluginRegistrant.java +**/android/key.properties +# *.jks + +# iOS/XCode related +**/ios/**/*.mode1v3 +**/ios/**/*.mode2v3 +**/ios/**/*.moved-aside +**/ios/**/*.pbxuser +**/ios/**/*.perspectivev3 +**/ios/**/*sync/ +**/ios/**/.sconsign.dblite +**/ios/**/.tags* +**/ios/**/.vagrant/ +**/ios/**/DerivedData/ +**/ios/**/Icon? +**/ios/**/Pods/ +**/ios/**/.symlinks/ +**/ios/**/profile +**/ios/**/xcuserdata +**/ios/.generated/ +**/ios/Flutter/.last_build_id +**/ios/Flutter/App.framework +**/ios/Flutter/Flutter.framework +**/ios/Flutter/Flutter.podspec +**/ios/Flutter/Generated.xcconfig +**/ios/Flutter/ephemeral +**/ios/Flutter/app.flx +**/ios/Flutter/app.zip +**/ios/Flutter/flutter_assets/ +**/ios/Flutter/flutter_export_environment.sh +**/ios/ServiceDefinitions.json +**/ios/Runner/GeneratedPluginRegistrant.* + +# macOS +**/macos/Flutter/GeneratedPluginRegistrant.swift + +# Coverage +coverage/ + +# Symbols +app.*.symbols + +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +!/dev/ci/**/Gemfile.lock + + +## Related .gitignores ## + +# Firebase configuration files / Google Services (e.g. APIs or Firebase) +ios/Runner/GoogleService-Info.plist +android/app/google-services.json + +# Google Maps API +google_maps_api.xml + +# Web related +lib/generated_plugin_registrant.dart + +# Obfuscation related +app.*.map.json + + +### --------------------------- Dart.gitignore ------------------------- ### + +# See https://www.dartlang.org/guides/libraries/private-files + +# Files and directories created by pub +#.dart_tool/ +#.packages +#build/ +# If you're building an application, you may want to check-in your pubspec.lock +#pubspec.lock + +# Directory created by dartdoc +# If you don't generate documentation locally you can remove this line. +doc/api/ + +# dotenv environment variables file +.env* + +# Avoid committing generated Javascript files: +*.dart.js +*.info.json # Produced by the --dump-info flag. +*.js # When generated by dart2js. Don't specify *.js if your + # project includes source files written in JavaScript. +*.js_ +*.js.deps +*.js.map + +#.flutter-plugins +#.flutter-plugins-dependencies + + +### -------------------------- Swift.gitignore ------------------------ ### + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +#xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +#*.xcscmblueprint +#*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +#build/ +#DerivedData/ +#*.moved-aside +#*.pbxuser +#!default.pbxuser +#*.mode1v3 +#!default.mode1v3 +#*.mode2v3 +#!default.mode2v3 +#*.perspectivev3 +#!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager + +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. + Packages/ + Package.pins + Package.resolved + *.xcodeproj + +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project + .swiftpm + +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + + +### -------------------------- Java.gitignore -------------------------- ### + +# Compiled class file +#*.class + +# Log file +#*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +#*.jar +*.war +*.nar +*.ear +#*.zip +*.tar.gz +#*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + + +### -------------------------- Kotlin.gitignore ------------------------ ### + +#.DS_Store +.idea/shelf +/confluence/target +/dependencies/repo +/android.tests.dependencies +/dependencies/android.tests.dependencies +/dist +/local +/gh-pages +/ideaSDK +/clionSDK +/android-studio/sdk +#out/ +/tmp +/intellij +workspace.xml +*.versionsBackup +/idea/testData/debugger/tinyApp/classes* +/jps-plugin/testData/kannotator +/js/js.translator/testData/out/ +/js/js.translator/testData/out-min/ +/js/js.translator/testData/out-pir/ +#.gradle/ +#build/ +!**/src/**/build +!**/test/**/build +#*.iml +!**/testData/**/*.iml +.idea/remote-targets.xml +.idea/libraries/Gradle*.xml +.idea/libraries/Maven*.xml +.idea/artifacts/PILL_*.xml +.idea/artifacts/KotlinPlugin.xml +#.idea/modules +.idea/runConfigurations/JPS_*.xml +.idea/runConfigurations/PILL_*.xml +.idea/runConfigurations/_FP_*.xml +.idea/runConfigurations/_MT_*.xml +#.idea/libraries +#.idea/modules.xml +#.idea/gradle.xml +#.idea/compiler.xml +.idea/inspectionProfiles/profiles_settings.xml +.idea/.name +.idea/artifacts/dist_auto_* +.idea/artifacts/dist.xml +.idea/artifacts/ideaPlugin.xml +.idea/artifacts/kotlinc.xml +.idea/artifacts/kotlin_compiler_jar.xml +.idea/artifacts/kotlin_plugin_jar.xml +.idea/artifacts/kotlin_jps_plugin_jar.xml +.idea/artifacts/kotlin_daemon_client_jar.xml +.idea/artifacts/kotlin_imports_dumper_compiler_plugin_jar.xml +.idea/artifacts/kotlin_main_kts_jar.xml +.idea/artifacts/kotlin_compiler_client_embeddable_jar.xml +.idea/artifacts/kotlin_reflect_jar.xml +.idea/artifacts/kotlin_stdlib_js_ir_* +.idea/artifacts/kotlin_test_js_ir_* +.idea/artifacts/kotlin_stdlib_wasm_* +.idea/artifacts/kotlinx_atomicfu_runtime_* +#.idea/jarRepositories.xml +.idea/csv-plugin.xml +.idea/libraries-with-intellij-classes.xml +.idea/misc.xml +node_modules/ +.rpt2_cache/ +libraries/tools/kotlin-test-js-runner/lib/ +#local.properties +buildSrcTmp/ +distTmp/ +outTmp/ +/test.output +/kotlin-native/dist +kotlin-ide/ + + +### ------------------------- Android.gitignore ------------------------ ### + +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Generated files +bin/ +gen/ +out/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +#fastlane/report.xml +#fastlane/Preview.html +fastlane/screenshots +#fastlane/test_output +fastlane/readme.md + +# Keystore files +*.jks +*.keystore + + +### ------------------------- Gradle.gitignore ------------------------- ### + +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +#.project +# JDT-specific (Eclipse Java Development Tools) +#.classpath + + +### ------------------------- Maven.gitignore -------------------------- ### + +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +#.project +# JDT-specific (Eclipse Java Development Tools) +#.classpath + + +### ------------------------ JetBrains.gitignore ----------------------- ### + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. + .idea/artifacts + .idea/compiler.xml + .idea/jarRepositories.xml + .idea/modules.xml + .idea/*.iml + .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +#*.iws + +# IntelliJ +#out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + + +### ------------------------- Xcode.gitignore -------------------------- ### + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +#build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno + + +### -------------------- VisualStudioCode.gitignore ------------------- ### + +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + + +### ----------------------- SublimeText.gitignore ---------------------- ### + +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json +sftp-config-alt*.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + + +### -------------------------- Emacs.gitignore ------------------------- ### + +# -*- mode: gitignore; -*- +#*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + + +### -------------------------- Vim.gitignore -------------------------- ### + +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +#*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + + +### ------------------------ Windows.gitignore ------------------------ ### + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### ------------------------- macOS.gitignore -------------------------- ### + +# General +#.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### -------------------------- Linux.gitignore ------------------------- ### + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + + +### ------------------------ Archives.gitignore ------------------------ ### + +# It's better to unpack these files and commit the raw source because +# git has its own built in compression methods. +*.7z +*.jar +*.rar +*.zip +*.gz +*.gzip +*.tgz +*.bzip +*.bzip2 +*.bz2 +*.xz +*.lzma +#*.cab +*.xar + +# Packing-only formats +*.iso +*.tar + +# Package management formats +*.dmg +*.xpi +*.gem +*.egg +*.deb +*.rpm +#*.msi +#*.msm +#*.msp +*.txz + + +### ------------------------- Backup.gitignore ------------------------- ### + +*.bak +*.gho +*.ori +*.orig +*.tmp + + +### -------------------------- JEnv.gitignore -------------------------- ### + +# JEnv local Java version configuration file +.java-version + +# Used by previous versions of JEnv +.jenv-version diff --git a/example/Framework_Verify.dart b/example/Framework_Verify.dart index 4430d93..d972a54 100644 --- a/example/Framework_Verify.dart +++ b/example/Framework_Verify.dart @@ -1,76 +1,72 @@ import 'dart:html'; + import 'package:puremvc/puremvc.dart' as mvc; class Framework_Verify { + Framework_Verify() {} - Framework_Verify() { - } - - void verify() - { + void verify() { String multitonKey = "Test Core"; String dataPoint1 = "Hello"; String dataPoint2 = "World"; String proxyName = "DataProxy"; - List retrievedObject; + List? retrievedObject; String badJuju = ""; try { - write ("
    "); + write("
      "); // Get a Facade - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); - write ("
    • Facade created for ${multitonKey}."); + mvc.IFacade facade = mvc.Facade.getInstance(multitonKey)!; + write("
    • Facade created for ${multitonKey}."); // Create some data - List dataObject = new List(); - write ("
    • Data Object (List<String>) created.
    • "); + List dataObject = List.empty(growable: true); + write("
    • Data Object (List<String>) created.
    • "); dataObject.add(dataPoint1); - write ("
    • Data point added '${dataPoint1}'.
    • "); + write("
    • Data point added '${dataPoint1}'.
    • "); dataObject.add(dataPoint2); - write ("
    • Data point added '${dataPoint2}'.
    • "); + write("
    • Data point added '${dataPoint2}'.
    • "); // Register a Proxy to hold the data - mvc.IProxy proxy = new mvc.Proxy( proxyName, dataObject ); - write( "
    • Proxy '${proxyName}' created with for Data Object.
    • "); - facade.registerProxy( proxy ); - write ("
    • Proxy '${proxyName}' registered with Model, via Facade.
    • "); + mvc.IProxy proxy = new mvc.Proxy(proxyName, dataObject); + write("
    • Proxy '${proxyName}' created with for Data Object.
    • "); + facade.registerProxy(proxy); + write("
    • Proxy '${proxyName}' registered with Model, via Facade.
    • "); // Now retrieve the Proxy - mvc.IProxy retrievedProxy = facade.retrieveProxy( proxyName ); - write ("
    • Proxy '${proxyName}' retrieved from Model, via Facade.
    • "); + mvc.IProxy retrievedProxy = facade.retrieveProxy(proxyName); + write("
    • Proxy '${proxyName}' retrieved from Model, via Facade.
    • "); // And get the data retrievedObject = retrievedProxy.getData(); - write ("
    • Data Object (List<String>) retrieved from ${proxyName}
    • "); - write("
    • Data Object (List<String>) Length: ${retrievedObject.length}
    • " ); + write("
    • Data Object (List<String>) retrieved from ${proxyName}
    • "); + write("
    • Data Object (List<String>) Length: ${retrievedObject!.length}
    • "); write("
    • Contents: ${retrievedObject[0]} ${retrievedObject[1]}
    • "); - write ("
    "); + write("
"); // Prove errors will be reported // throw "Fungers! I've got jelly in my ears!"; - - } on Error catch ( e ) { + } on Error catch (e) { // Catch any error badJuju = e.toString(); - } finally { // Report final status - if ( badJuju.length == 0 && retrievedObject != null - && retrievedObject[0] == dataPoint1 - && retrievedObject[1] == dataPoint2 ){ - write( "

Science! PureMVC is purring like a kitten. Take her out for a spin!"); + if (badJuju.length == 0 && + retrievedObject != null && + retrievedObject[0] == dataPoint1 && + retrievedObject[1] == dataPoint2) { + write("

Science! PureMVC is purring like a kitten. Take her out for a spin!"); } else { - write( "

Claptrap! Someone's thrown a spanner in the works."); - if( badJuju.length>0 ) write( "Bad juju reported: ${badJuju}"); + write("

Claptrap! Someone's thrown a spanner in the works."); + if (badJuju.length > 0) write("Bad juju reported: ${badJuju}"); } } - } void write(String message) { // the HTML library defines a global "document" variable - document.querySelector('#text').innerHtml = "${document.querySelector('#text').innerHtml}${message}"; + document.querySelector('#text')?.innerHtml = "${document.querySelector('#text')?.innerHtml}${message}"; } } diff --git a/example/Framework_Verify.html b/example/Framework_Verify.html index bf7d8ad..f0e3fe9 100644 --- a/example/Framework_Verify.html +++ b/example/Framework_Verify.html @@ -14,7 +14,6 @@

Framework Verification Page

- - diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index 8bff399..edf6068 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -14,9 +14,7 @@ part of puremvc; * * See [INotification], [ICommand] */ -class Controller implements IController -{ - +class Controller implements IController { /** * Constructor. * @@ -25,12 +23,11 @@ class Controller implements IController * * - Throws [MultitonErrorControllerExists] if instance for this Multiton key has already been constructed */ - Controller( String key ) - { - if ( instanceMap[ key ] != null ) throw new MultitonErrorControllerExists(); - multitonKey = key; - instanceMap[ multitonKey ] = this; - commandMap = new Map(); + Controller(String key) { + if (instanceMap.containsKey(key)) throw MultitonErrorControllerExists(); + _multitonKey = key; + instanceMap[_multitonKey] = this; + commandMap = Map(); initializeController(); } @@ -43,9 +40,8 @@ class Controller implements IController * you should also subclass [Controller] and override the [initializeController] method, * setting [view] equal to the return value of a call to [getInstance] on your [IView] implementor. */ - void initializeController( ) - { - view = View.getInstance( multitonKey ); + void initializeController() { + view = View.getInstance(multitonKey)!; } /** @@ -53,12 +49,13 @@ class Controller implements IController * * - Returns the [IController] Multiton instance for the specified key */ - static IController getInstance( String key ) - { - if ( key == null || key == "" ) return null; - if ( instanceMap == null ) instanceMap = new Map(); - if ( instanceMap[ key ] == null ) instanceMap[ key ] = new Controller( key ); - return instanceMap[ key ]; + static IController? getInstance(String? key) { + if (key == null || key == "") return null; + if (instanceMap.containsKey(key)) { + return instanceMap[key]; + } else { + return instanceMap[key] = Controller(key); + } } /** @@ -67,14 +64,14 @@ class Controller implements IController * * - Param [note] - the [INotification] to execute the associated [ICommand] for */ - void executeCommand( INotification note ) - { - Function commandFactory = commandMap[ note.getName() ]; - if ( commandFactory == null ) return; + void executeCommand(INotification note) { + final noteName = note.getName(); + Function? commandFactory = commandMap[noteName]; + if (commandFactory == null) return; ICommand commandInstance = commandFactory(); - commandInstance.initializeNotifier( multitonKey ); - commandInstance.execute( note ); + commandInstance.initializeNotifier(multitonKey); + commandInstance.execute(note); } /** @@ -83,12 +80,11 @@ class Controller implements IController * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ - void registerCommand( String noteName, Function commandFactory ) - { - if ( commandMap[ noteName ] == null ) { - view.registerObserver( noteName, new Observer( executeCommand, this ) ); + void registerCommand(String noteName, Function commandFactory) { + if (commandMap[noteName] == null) { + view.registerObserver(noteName, new Observer(executeCommand, this)); } - commandMap[ noteName ] = commandFactory; + commandMap[noteName] = commandFactory; } /** @@ -97,9 +93,8 @@ class Controller implements IController * - Param [noteName] - the name of the [INotification]. * - Returns [bool] - whether an [ICommand] is currently registered for the given [noteName]. */ - bool hasCommand( String noteName ) - { - return commandMap[ noteName ] != null; + bool hasCommand(String noteName) { + return commandMap[noteName] != null; } /** @@ -107,16 +102,14 @@ class Controller implements IController * * - Param [noteName] - the name of the [INotification] to remove the [ICommand] mapping for. */ - void removeCommand( String noteName ) - { + void removeCommand(String noteName) { // if the Command is registered... - if ( hasCommand( noteName ) ) - { + if (hasCommand(noteName)) { // remove the observer - view.removeObserver( noteName, this ); + view.removeObserver(noteName, this); // remove the command - commandMap[ noteName ] = null; + commandMap.remove(noteName); } } @@ -125,23 +118,22 @@ class Controller implements IController * * - Param [key] multitonKey of the [IController] instance to remove */ - static void removeController( String key ) - { - instanceMap[ key ] = null; + static void removeController(String key) { + instanceMap.remove(key); } // Local reference to this core's IView - IView view; + late IView view; // Mapping of Notification names to Command Class references - Map commandMap; + late Map commandMap; // The Multiton Key for this Core - String multitonKey; + late String _multitonKey; + String get multitonKey => _multitonKey; // Multiton instance map - static Map instanceMap; - + static Map instanceMap = Map(); } class MultitonErrorControllerExists { diff --git a/lib/src/core/Model.dart b/lib/src/core/Model.dart index 56aaeb5..5894bc2 100644 --- a/lib/src/core/Model.dart +++ b/lib/src/core/Model.dart @@ -19,8 +19,7 @@ part of puremvc; * * See [IProxy], [IFacade] */ -class Model implements IModel -{ +class Model implements IModel { /** * Constructor. * @@ -29,12 +28,11 @@ class Model implements IModel * * - Throws [MultitonErrorModelExists] if instance for this Multiton key instance has already been constructed. */ - Model( String key ) - { - if ( instanceMap[ key ] != null ) throw new MultitonErrorModelExists(); - multitonKey = key; - instanceMap[ multitonKey ] = this; - proxyMap = new Map(); + Model(String key) { + if (instanceMap.containsKey(key)) throw MultitonErrorModelExists(); + _multitonKey = key; + instanceMap[_multitonKey] = this; + proxyMap = Map(); initializeModel(); } @@ -44,19 +42,20 @@ class Model implements IModel * Called automatically by the constructor, this is your opportunity to initialize the Singleton * instance in your subclass without overriding the constructor. */ - void initializeModel( ){ } + void initializeModel() {} /** * [IModel] Multiton Factory method. * * - Returns the [IModel] Multiton instance for the specified key. */ - static IModel getInstance( String key ) - { - if ( key == null || key == "" ) return null; - if ( instanceMap == null ) instanceMap = new Map(); - if ( instanceMap[ key ] == null ) instanceMap[ key ] = new Model( key ); - return instanceMap[ key ]; + static IModel? getInstance(String? key) { + if (key == null || key == "") return null; + if (instanceMap.containsKey(key)) { + return instanceMap[key]; + } else { + return instanceMap[key] = Model(key); + } } /** @@ -64,10 +63,10 @@ class Model implements IModel * * - Param [proxy] - an object reference to be held by the [IModel]. */ - void registerProxy( IProxy proxy ) - { - proxy.initializeNotifier( multitonKey ); - proxyMap[ proxy.getName() ] = proxy; + void registerProxy(IProxy proxy) { +// print("> Framework -> Model > registerProxy: " + proxy.getName()); + proxy.initializeNotifier(multitonKey); + proxyMap[proxy.getName()] = proxy; proxy.onRegister(); } @@ -77,9 +76,8 @@ class Model implements IModel * - Param [proxyName] - the name of the [IProxy] instance to retrieve. * - Returns the [IProxy] instance previously registered with the given [proxyName]. */ - IProxy retrieveProxy( String proxyName ) - { - return proxyMap[ proxyName ]; + IProxy retrieveProxy(String proxyName) { + return proxyMap[proxyName]!; } /** @@ -88,14 +86,10 @@ class Model implements IModel * - Param [proxyName] - name of the [IProxy] instance to be removed. * - Returns [IProxy] - the [IProxy] that was removed from the [IModel]. */ - IProxy removeProxy( String proxyName ) - { - IProxy proxy = proxyMap[ proxyName ]; - if ( proxy != null ) - { - proxyMap[ proxyName ] = null; - proxy.onRemove(); - } + IProxy removeProxy(String proxyName) { + IProxy proxy = proxyMap[proxyName]!; + proxyMap.remove(proxyName); + proxy.onRemove(); return proxy; } @@ -105,9 +99,8 @@ class Model implements IModel * - Param [proxyName] - the name of the [IProxy] instance you're looking for. * - Returns [bool] - whether an [IProxy] is currently registered with the given [proxyName]. */ - bool hasProxy( String proxyName ) - { - return proxyMap[ proxyName ] != null; + bool hasProxy(String proxyName) { + return proxyMap.containsKey(proxyName); } /** @@ -115,19 +108,19 @@ class Model implements IModel * * - Param [key] - the multitonKey of [IModel] instance to remove */ - static void removeModel( String key ) - { - instanceMap[ key ] = null; + static void removeModel(String key) { + instanceMap.remove(key); } // Mapping of proxyNames to IProxy instances - Map proxyMap; + late Map proxyMap; // Multiton instance map - static Map instanceMap; + static Map instanceMap = Map(); // The Multiton Key for this Core - String multitonKey; + late String _multitonKey; + String get multitonKey => _multitonKey; } class MultitonErrorModelExists { diff --git a/lib/src/core/View.dart b/lib/src/core/View.dart index 9d88df7..308995d 100644 --- a/lib/src/core/View.dart +++ b/lib/src/core/View.dart @@ -14,9 +14,7 @@ part of puremvc; * * See [IMediator], [IObserver], [INotification] */ -class View implements IView -{ - +class View implements IView { /** * Constructor. * @@ -25,13 +23,12 @@ class View implements IView * * - Throws [MultitonErrorViewExists] if instance for this Multiton key has already been constructed */ - View( String key ) - { - if (instanceMap[ key ] != null) throw new MultitonErrorViewExists(); - multitonKey = key; - instanceMap[ multitonKey ] = this; - mediatorMap = new Map(); - observerMap = new Map>(); + View(String key) { + if (instanceMap.containsKey(key)) throw MultitonErrorViewExists(); + _multitonKey = key; + instanceMap[_multitonKey] = this; + mediatorMap = Map(); + observerMap = Map>(); initializeView(); } @@ -41,19 +38,20 @@ class View implements IView * Called automatically by the constructor, this is your opportunity to initialize the Multiton * instance in your subclass without overriding the constructor. */ - void initializeView( ){} + void initializeView() {} /** * [IView] Multiton Factory method. * * - Returns the [IView] Multiton instance for the specified key. */ - static IView getInstance( String key ) - { - if ( key == null || key == "" ) return null; - if ( instanceMap == null ) instanceMap = new Map(); - if ( instanceMap[ key ] == null ) instanceMap[ key ] = new View( key ); - return instanceMap[ key ]; + static IView? getInstance(String? key) { + if (key == null || key == "") return null; + if (instanceMap.containsKey(key)) { + return instanceMap[key]; + } else { + return instanceMap[key] = View(key); + } } /** @@ -62,12 +60,11 @@ class View implements IView * - Param [noteName] - the name of the [INotification] to notify this [IObserver] of. * - Param [observer] - the [IObserver] to register. */ - void registerObserver( String noteName, IObserver observer ) - { - if( observerMap[ noteName ] == null ) { - observerMap[ noteName ] = new List(); - } - observerMap[ noteName ].add( observer ); + void registerObserver(String noteName, IObserver observer) { + final hasObserversList = observerMap.containsKey(noteName); + var observers = hasObserversList ? observerMap[noteName] : List.empty(growable: true); + if (!hasObserversList) observerMap[noteName] = observers; + observers!.add(observer); } /** @@ -79,25 +76,20 @@ class View implements IView * * - Param [note] - the [INotification] to notify [IObservers] of. */ - void notifyObservers( INotification note ) - { + void notifyObservers(INotification note) { // Get a reference to the observers list for this notification name - List observers_ref = observerMap[ note.getName() ]; - if( observers_ref != null ) - { + final noteName = note.getName(); + final hasObserversList = observerMap.containsKey(noteName); + if (hasObserversList) { + final observers_ref = observerMap[noteName]!; // Copy observers from reference array to working array, // since the reference array may change during the notification loop - List observers = new List(); + List observersCopy = List.from(observers_ref); IObserver observer; - for (var i = 0; i < observers_ref.length; i++) { - observer = observers_ref[ i ]; - observers.add( observer ); - } - // Notify Observers from the working array - for (var i = 0; i < observers.length; i++) { - observer = observers[ i ]; - observer.notifyObserver( note ); + for (var i = 0; i < observersCopy.length; i++) { + observer = observersCopy[i]; + observer.notifyObserver(note); } } } @@ -108,28 +100,27 @@ class View implements IView * - Param [noteName] - which [IObserver] list to remove from. * - Param [notifyContext] - remove [IObserver]s with this object as the [notifyContext]. */ - void removeObserver( String noteName, Object notifyContext ) - { - // the observer list for the notification under inspection - List observers = observerMap[ noteName ]; - - // find the observer for the notifyContext - for ( var i=0; i observers = observerMap[noteName]!; + IObserver observer; + // find the observer for the notifyContext + for (var i = 0; i < observers.length; i++) { + observer = observers[i]; + if (observer.compareNotifyContext(notifyContext) == true) { + // there can only be one Observer for a given notifyContext + // in any given Observer list, so remove it and break + observers.remove(observer); + break; } + } - // Also, when a Notification's Observer list length falls to - // zero, delete the notification key from the observer map - if ( observers.length == 0 ) { - observerMap[ noteName ] = null; - } + // Also, when a Notification's Observer list length falls to + // zero, delete the notification key from the observer map + if (observers.length == 0) { + observerMap.remove(noteName); + } } /** @@ -146,29 +137,27 @@ class View implements IView * * - Param [mediator] - a reference to the [IMediator] instance. */ - void registerMediator( IMediator mediator ) - { + void registerMediator(IMediator mediator) { // do not allow re-registration (you must call removeMediator first) - if ( mediatorMap[ mediator.getName() ] != null ) return; + if (mediatorMap.containsKey(mediator.getName())) return; // Initialize with multiton key - mediator.initializeNotifier( multitonKey ); + mediator.initializeNotifier(multitonKey); // Register the Mediator for retrieval by name - mediatorMap[ mediator.getName() ] = mediator; + mediatorMap[mediator.getName()] = mediator; // Get Notification interests, if any. List interests = mediator.listNotificationInterests(); // Register Mediator as an observer for each notification of interests - if ( interests.length > 0 ) - { + if (interests.length > 0) { // Create Observer referencing this mediator's handlNotification method - IObserver observer = new Observer( mediator.handleNotification, mediator ); + IObserver observer = Observer(mediator.handleNotification, mediator); // Register Mediator as Observer for its list of Notification interests - for ( var i=0; i interests = mediator.listNotificationInterests(); - for ( var i=0; i interests = mediator.listNotificationInterests(); + for (var i = 0; i < interests.length; i++) { + // remove the observer linking the mediator + // to the notification interest + removeObserver(interests[i], mediator); + } - // remove the mediator from the map - mediatorMap[ mediatorName ] = null; + // remove the mediator from the map + mediatorMap.remove(mediatorName); - // alert the mediator that it has been removed - mediator.onRemove(); - } + // alert the mediator that it has been removed + mediator.onRemove(); - return mediator; + return mediator; } /** @@ -225,9 +208,8 @@ class View implements IView * - Param [mediatorName] - the name of the [IMediator] you're looking for. * - Returns [bool] - whether an [IMediator] is registered in this core with the given [mediatorName]. */ - bool hasMediator( String mediatorName ) - { - return mediatorMap[ mediatorName ] != null; + bool hasMediator(String mediatorName) { + return mediatorMap.containsKey(mediatorName); } /** @@ -235,22 +217,22 @@ class View implements IView * * - Param [key] - the Multiton key of [IView] instance to remove. */ - static void removeView( String key ) - { - instanceMap[ key ] = null; + static void removeView(String key) { + instanceMap.remove(key); } // Mapping of IMediator names to IMediator instances - Map mediatorMap; + late Map mediatorMap; // Mapping of INotification names to IObserver lists - Map> observerMap; + late Map?> observerMap; // Multiton IView instance map - static Map instanceMap; + static Map instanceMap = Map(); // The Multiton key for this Core - String multitonKey; + late String _multitonKey; + String get multitonKey => _multitonKey; } class MultitonErrorViewExists { @@ -260,4 +242,3 @@ class MultitonErrorViewExists { return "IViewMultiton instance already constructed for this key."; } } - diff --git a/lib/src/interfaces/ICommand.dart b/lib/src/interfaces/ICommand.dart index c3a2414..6a5e8cb 100644 --- a/lib/src/interfaces/ICommand.dart +++ b/lib/src/interfaces/ICommand.dart @@ -5,12 +5,11 @@ part of puremvc; * * See [IController], [INotification] */ -abstract class ICommand extends INotifier -{ +abstract class ICommand extends INotifier { /** * Execute the [ICommand]'s logic to handle a given [INotification]. * * - Param [note] - an [INotification] to handle. */ - void execute( INotification note ); + void execute(INotification note); } diff --git a/lib/src/interfaces/IController.dart b/lib/src/interfaces/IController.dart index ad8b937..53b0fca 100644 --- a/lib/src/interfaces/IController.dart +++ b/lib/src/interfaces/IController.dart @@ -14,15 +14,14 @@ part of puremvc; * * See [INotification], [ICommand] */ -abstract class IController -{ +abstract class IController { /** * Register an [INotification] to [ICommand] mapping with the [IController]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ - void registerCommand( String notificationName, Function commandFactory ); + void registerCommand(String notificationName, Function commandFactory); /** * Execute the [ICommand] previously registered as the @@ -30,14 +29,14 @@ abstract class IController * * - Param [note] - the [INotification] to execute the associated [ICommand] for */ - void executeCommand( INotification note ); + void executeCommand(INotification note); /** * Remove a previously registered [INotification] to [ICommand] mapping from the [IController]. * * - Param [noteName] - the name of the [INotification] to remove the [ICommand] mapping for. */ - void removeCommand( String noteName ); + void removeCommand(String noteName); /** * Check if an [ICommand] is registered for a given [INotification] name with the [IController]. @@ -45,12 +44,10 @@ abstract class IController * - Param [noteName] - the name of the [INotification]. * - Returns [bool] - whether an [ICommand] is currently registered for the given [noteName]. */ - bool hasCommand( String noteName ); + bool hasCommand(String noteName); /** * This IController's Multiton Key */ - void set multitonKey( String key ); String get multitonKey; - } diff --git a/lib/src/interfaces/IFacade.dart b/lib/src/interfaces/IFacade.dart index ba5b5c1..dce4583 100644 --- a/lib/src/interfaces/IFacade.dart +++ b/lib/src/interfaces/IFacade.dart @@ -22,153 +22,150 @@ part of puremvc; * * See [IModel], [IView], [IController], [IProxy], [IMediator], [ICommand], [INotification] */ -abstract class IFacade extends INotifier -{ - - /** - * Register an [IProxy] instance with the [IModel]. - * - * - Param [proxy] - an object reference to be held by the [IModel]. - */ - void registerProxy( IProxy proxy ); - - /** - * Retrieve an [IProxy] instance from the [IModel]. - * - * - Param [proxyName] - the name of the [IProxy] instance to retrieve. - * - Returns the [IProxy] instance previously registered with the given [proxyName]. - */ - IProxy retrieveProxy( String proxyName ); - - /** - * Remove an [IProxy] instance from the [IModel]. - * - * - Param [proxyName] - name of the [IProxy] instance to be removed. - * - Returns [IProxy] - the [IProxy] that was removed from the [IModel]. - */ - IProxy removeProxy( String proxyName ); - - /** - * Check if an [IProxy] is registered with the [IModel]. - * - * - Param [proxyName] - the name of the [IProxy] instance you're looking for. - * - Returns [bool] - whether an [IProxy] is currently registered with the given [proxyName]. - */ - bool hasProxy( String proxyName ); - - /** - * Register an [INotification] to [ICommand] mapping with the [IController]. - * - * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. - */ - void registerCommand( String noteName, Function commandFactory ); - - /** - * Remove a previously registered [INotification] to [ICommand] mapping from the [IController]. - * - * - Param [noteName] - the name of the [INotification] to remove the [ICommand] mapping for. - */ - void removeCommand( String noteName ); - - /** - * Check if an [ICommand] is registered for a given [INotification] name with the [IController]. - * - * - Param [noteName] - the name of the [INotification]. - * - Returns [bool] - whether an [ICommand] is currently registered for the given [noteName]. - */ - bool hasCommand( String noteName ); - - /** - * Register an [IMediator] instance with the [IView]. - * - * Registers the [IMediator] so that it can be retrieved by name, - * and interrogates the [IMediator] for its [INotification] interests. - * - * If the [IMediator] returns a list of [INotification] - * names to be notified about, an [Observer] is created encapsulating - * the [IMediator] instance's [handleNotification] method - * and registering it as an [IObserver] for all [INotification]s the - * [IMediator] is interested in. - * - * - Param [mediator] - a reference to the [IMediator] instance. - */ - void registerMediator( IMediator mediator ); - - /** - * Retrieve an [IMediator] from the [IView]. - * - * - Param [mediatorName] - the name of the [IMediator] instance to retrieve. - * - Returns [IMediator] - the [IMediator] instance previously registered in this core with the given [mediatorName]. - */ - IMediator retrieveMediator( String mediatorName ); - - /** - * Remove an [IMediator] from the [IView]. - * - * - Param [mediatorName] - name of the [IMediator] instance to be removed. - * - Returns [IMediator] - the [IMediator] that was removed from this core's [IView]. - */ - IMediator removeMediator( String mediatorName ); - - /** - * Check if an [IMediator] is registered with the [IView]. - * - * - Param [mediatorName] - the name of the [IMediator] you're looking for. - * - Returns [bool] - whether an [IMediator] is registered in this core with the given [mediatorName]. - */ - bool hasMediator( String mediatorName ); - - /** - * Register an [IObserver] to be notified of [INotification]s with a given name. - * - * - Param [noteName] - the name of the [INotification] to notify this [IObserver] of. - * - Param [observer] - the [IObserver] to register. - */ - void registerObserver( String noteName, IObserver observer ); - - /** - * Remove an [IObserver] from the list for a given [INotification] name. - * - * - Param [noteName] - which [IObserver] list to remove from. - * - Param [notifyContext] - remove [IObserver]s with this object as the [notifyContext]. - */ - void removeObserver( String noteName, Object notifyContext ); - - /** - * Notify [IObserver]s. - * - * This method allows you to send custom [INotification] classes using the [IFacade]. - * - * Usually you should just call [sendNotification] and pass the parameters, - * never having to construct an [INotification] yourself. - * - * - Param [note] the [INotification] to have the [View] notify [Observers] of. - */ - void notifyObservers( INotification notification ); - - /** - * This [IFacade]'s Multiton key - */ - void set multitonKey( String key ); - String get multitonKey; - - /** - * This [IFacade]'s [IModel] - */ - void set model( IModel modelInstance ); - IModel get model; - - /** - * This [IFacade]'s [IView] - */ - void set view( IView viewInstance ); - IView get view; - - /** - * This [IFacade]'s [IController] - */ - void set controller( IController controllerInstance ); - IController get controller; - +abstract class IFacade extends INotifier { + /** + * Register an [IProxy] instance with the [IModel]. + * + * - Param [proxy] - an object reference to be held by the [IModel]. + */ + registerProxy(IProxy proxy); + + /** + * Retrieve an [IProxy] instance from the [IModel]. + * + * - Param [proxyName] - the name of the [IProxy] instance to retrieve. + * - Returns the [IProxy] instance previously registered with the given [proxyName]. + */ + IProxy retrieveProxy(String proxyName); + + /** + * Remove an [IProxy] instance from the [IModel]. + * + * - Param [proxyName] - name of the [IProxy] instance to be removed. + * - Returns [IProxy] - the [IProxy] that was removed from the [IModel]. + */ + IProxy? removeProxy(String proxyName); + + /** + * Check if an [IProxy] is registered with the [IModel]. + * + * - Param [proxyName] - the name of the [IProxy] instance you're looking for. + * - Returns [bool] - whether an [IProxy] is currently registered with the given [proxyName]. + */ + bool hasProxy(String proxyName); + + /** + * Register an [INotification] to [ICommand] mapping with the [IController]. + * + * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. + * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. + */ + void registerCommand(String noteName, Function commandFactory); + void executeCommand(String noteName, [dynamic body = null, String? type]); + + /** + * Remove a previously registered [INotification] to [ICommand] mapping from the [IController]. + * + * - Param [noteName] - the name of the [INotification] to remove the [ICommand] mapping for. + */ + void removeCommand(String noteName); + + /** + * Check if an [ICommand] is registered for a given [INotification] name with the [IController]. + * + * - Param [noteName] - the name of the [INotification]. + * - Returns [bool] - whether an [ICommand] is currently registered for the given [noteName]. + */ + bool hasCommand(String noteName); + + /** + * Register an [IMediator] instance with the [IView]. + * + * Registers the [IMediator] so that it can be retrieved by name, + * and interrogates the [IMediator] for its [INotification] interests. + * + * If the [IMediator] returns a list of [INotification] + * names to be notified about, an [Observer] is created encapsulating + * the [IMediator] instance's [handleNotification] method + * and registering it as an [IObserver] for all [INotification]s the + * [IMediator] is interested in. + * + * - Param [mediator] - a reference to the [IMediator] instance. + */ + void registerMediator(IMediator mediator); + + /** + * Retrieve an [IMediator] from the [IView]. + * + * - Param [mediatorName] - the name of the [IMediator] instance to retrieve. + * - Returns [IMediator] - the [IMediator] instance previously registered in this core with the given [mediatorName]. + */ + IMediator retrieveMediator(String mediatorName); + + /** + * Remove an [IMediator] from the [IView]. + * + * - Param [mediatorName] - name of the [IMediator] instance to be removed. + * - Returns [IMediator] - the [IMediator] that was removed from this core's [IView]. + */ + IMediator? removeMediator(String mediatorName); + + /** + * Check if an [IMediator] is registered with the [IView]. + * + * - Param [mediatorName] - the name of the [IMediator] you're looking for. + * - Returns [bool] - whether an [IMediator] is registered in this core with the given [mediatorName]. + */ + bool hasMediator(String mediatorName); + + /** + * Register an [IObserver] to be notified of [INotification]s with a given name. + * + * - Param [noteName] - the name of the [INotification] to notify this [IObserver] of. + * - Param [observer] - the [IObserver] to register. + */ + void registerObserver(String noteName, IObserver observer); + + /** + * Remove an [IObserver] from the list for a given [INotification] name. + * + * - Param [noteName] - which [IObserver] list to remove from. + * - Param [notifyContext] - remove [IObserver]s with this object as the [notifyContext]. + */ + void removeObserver(String noteName, Object notifyContext); + + /** + * Notify [IObserver]s. + * + * This method allows you to send custom [INotification] classes using the [IFacade]. + * + * Usually you should just call [sendNotification] and pass the parameters, + * never having to construct an [INotification] yourself. + * + * - Param [note] the [INotification] to have the [View] notify [Observers] of. + */ + void notifyObservers(INotification notification); + + /** + * This [IFacade]'s Multiton key + */ + String? get multitonKey; + + /** + * This [IFacade]'s [IModel] + */ + void set model(IModel? modelInstance); + IModel? get model; + + /** + * This [IFacade]'s [IView] + */ + void set view(IView? viewInstance); + IView? get view; + + /** + * This [IFacade]'s [IController] + */ + void set controller(IController? controllerInstance); + IController? get controller; } diff --git a/lib/src/interfaces/IMediator.dart b/lib/src/interfaces/IMediator.dart index 8007084..7554e5c 100644 --- a/lib/src/interfaces/IMediator.dart +++ b/lib/src/interfaces/IMediator.dart @@ -23,9 +23,7 @@ part of puremvc; * * See [INotification], [IView] */ -abstract class IMediator extends INotifier -{ - +abstract class IMediator extends INotifier { /** * Get the [IMediator] instance's [name]. * @@ -45,43 +43,41 @@ abstract class IMediator extends INotifier * * - Param [Dynamic] - the [viewComponent]. */ - void setViewComponent( dynamic viewComponent ); + void setViewComponent(dynamic viewComponent); /** * List [INotification] interests. * * - Returns [List] - a [List] of the [INotification] names this [IMediator] has an interest in. */ - List listNotificationInterests( ); + List listNotificationInterests(); /** * Handle an [INotification]. * * - Param [note] - the [INotification] to be handled. */ - void handleNotification( INotification note ); + void handleNotification(INotification note); /** * Called by the [IView] when the [IMediator] is registered. */ - void onRegister( ); + void onRegister(); /** * Called by the [IView] when the [IMediator] is removed. */ - void onRemove( ); - + void onRemove(); /** * This [IMediator]'s [viewComponent]. */ - void set viewComponent( dynamic viewComponent ); + void set viewComponent(dynamic viewComponent); dynamic get viewComponent; /** * This [IMediator]'s [name]. */ - void set name( String mediatorName ); + void set name(String mediatorName); String get name; - -} \ No newline at end of file +} diff --git a/lib/src/interfaces/IModel.dart b/lib/src/interfaces/IModel.dart index 63284a8..ef466b4 100644 --- a/lib/src/interfaces/IModel.dart +++ b/lib/src/interfaces/IModel.dart @@ -18,43 +18,40 @@ part of puremvc; * * See [IProxy], [IFacade] */ -abstract class IModel -{ - /** +abstract class IModel { + /** * Register an [IProxy] instance with the [IModel]. * * - Param [proxy] - an object reference to be held by the [IModel]. */ - void registerProxy( IProxy proxy ); + void registerProxy(IProxy proxy); - /** + /** * Retrieve an [IProxy] instance from the [IModel]. * * - Param [proxyName] - the name of the [IProxy] instance to retrieve. * - Returns the [IProxy] instance previously registered with the given [proxyName]. */ - IProxy retrieveProxy( String proxyName ); + IProxy retrieveProxy(String proxyName); - /** + /** * Remove an [IProxy] instance from the [IModel]. * * - Param [proxyName] - name of the [IProxy] instance to be removed. * - Returns [IProxy] - the [IProxy] that was removed from the [IModel]. */ - IProxy removeProxy( String proxyName ); + IProxy removeProxy(String proxyName); - /** + /** * Check if an [IProxy] is registered with the [IModel]. * * - Param [proxyName] - the name of the [IProxy] instance you're looking for. * - Returns [bool] - whether an [IProxy] is currently registered with the given [proxyName]. */ - bool hasProxy( String proxyName ); + bool hasProxy(String proxyName); - /** + /** * This [IModel]'s Multiton Key */ - void set multitonKey( String key ); - String get multitonKey; - + String get multitonKey; } diff --git a/lib/src/interfaces/INotification.dart b/lib/src/interfaces/INotification.dart index 17d2c88..9df70bc 100644 --- a/lib/src/interfaces/INotification.dart +++ b/lib/src/interfaces/INotification.dart @@ -19,61 +19,39 @@ part of puremvc; * * See [IView], [IObserver] */ -abstract class INotification -{ - - /** - * Get the [name] of the [INotification]. - * - * - Returns [String] - the name of the [INotification]. - */ - String getName(); - - /** - * Set the [body] of the [INotification]. - * - * - Param [body] - the body of the [INotification]. - */ - void setBody( Object body ); - - /** - * Get the [body] of the [INotification]. - * - * - Returns [Dynamic] - the body of the [INotification]. - */ - dynamic getBody(); - - /** - * Set the [type] of the [INotification]. - * - * - Param [type] - the type of the [INotification]. - */ - void setType( String type ); - - /** - * Get the [type] of the [INotification]. - * - * - Returns [String] - the type of the [INotification]. - */ - String getType(); - - /** - * This [INotifications]'s [body] - */ - void set body( dynamic bodyObject ); - dynamic get body; - - /** - * This [INotifications]'s [name] - */ - void set name( String noteName ); - String get name; - - /** - * This [INotifications]'s [type] - */ - void set type( String noteType ); - String get type; - - +abstract class INotification { + /** + * Get the [name] of the [INotification]. + * + * - Returns [String] - the name of the [INotification]. + */ + String getName(); + + /** + * Set the [body] of the [INotification]. + * + * - Param [body] - the body of the [INotification]. + */ + void setBody(Object body); + + /** + * Get the [body] of the [INotification]. + * + * - Returns [Dynamic] - the body of the [INotification]. + */ + dynamic getBody(); + + /** + * Set the [type] of the [INotification]. + * + * - Param [type] - the type of the [INotification]. + */ + void setType(String? type); + + /** + * Get the [type] of the [INotification]. + * + * - Returns [String] - the type of the [INotification]. + */ + String? getType(); } diff --git a/lib/src/interfaces/INotifier.dart b/lib/src/interfaces/INotifier.dart index f369a07..70a9799 100644 --- a/lib/src/interfaces/INotifier.dart +++ b/lib/src/interfaces/INotifier.dart @@ -20,7 +20,6 @@ part of puremvc; * See [IFacade], [INotification] */ abstract class INotifier { - /** * Send an [INotification]. * @@ -31,24 +30,22 @@ abstract class INotifier { * - Param [body] - the body of the note (optional) * - Param [type] - the type of the note (optional) */ - void sendNotification( String noteName, [dynamic body, String type] ); + void sendNotification(String noteName, [dynamic body, String? type]); /** * Initialize this [INotifier] instance. * - * This is how a [INotifier] gets its [multitonKey]. + * This is how a [INotifier] gets its [_multitonKey]. * Calls to [sendNotification] or access to the * [facade] will fail until after this method * has been called. * * - Param [key] - the Multiton key for this [INotifier]. */ - void initializeNotifier( String key ); + void initializeNotifier(String? key); /** * This INotifier's Multiton Key */ - void set multitonKey( String key ); - String get multitonKey; - + String? get multitonKey; } diff --git a/lib/src/interfaces/IObserver.dart b/lib/src/interfaces/IObserver.dart index a9000c9..d793da9 100644 --- a/lib/src/interfaces/IObserver.dart +++ b/lib/src/interfaces/IObserver.dart @@ -25,64 +25,49 @@ part of puremvc; * * See [IView], [INotification] */ -abstract class IObserver -{ - /** - * Set the notification method. - * - * The notification method should take one parameter of type [INotification]. - * - * - Param [notifyMethod] - the notification (callback) method of the interested object. - */ - void setNotifyMethod( Function callback ); +abstract class IObserver { + /** + * Set the notification method. + * + * The notification method should take one parameter of type [INotification]. + * + * - Param [notifyMethod] - the notification (callback) method of the interested object. + */ + void setNotifyMethod(Function? callback); - /** - * Set the notification context. - * - * - Param [caller] - a reference to the object to be notified. - */ - void setNotifyContext( Object caller ); + /** + * Set the notification context. + * + * - Param [caller] - a reference to the object to be notified. + */ + void setNotifyContext(Object? caller); - /** - * Get the notification method. - * - * - Returns [Function] - the notification (callback) method of the interested object. - */ - Function getNotifyMethod(); + /** + * Get the notification method. + * + * - Returns [Function] - the notification (callback) method of the interested object. + */ + Function? getNotifyMethod(); - /** - * Get the notification context. - * - * - Returns [Object] - the caller. - */ - Object getNotifyContext(); + /** + * Get the notification context. + * + * - Returns [Object] - the caller. + */ + Object? getNotifyContext(); - /** - * Compare a given object to the [notifyContext] (caller) object. - * - * - Param [Object] - the object to compare. - * - Returns [bool] - whether the given object and the [notifyContext] (caller) are the same. - */ - bool compareNotifyContext( Object object ); - - /** - * Notify the interested object. - * - * - Param [note] - the [INotification] to pass to the caller's [notifyMethod]. - */ - void notifyObserver( INotification note ); - - /** - * This [IObserver]'s [notifyMethod] (i.e., callback) - */ - void set notifyMethod( Function callback ); - Function get notifyMethod; - - /** - * This [IObserver]'s [notifyContext] (i.e., caller) - */ - void set notifyContext( Object caller ); - Object get notifyContext; + /** + * Compare a given object to the [notifyContext] (caller) object. + * + * - Param [Object] - the object to compare. + * - Returns [bool] - whether the given object and the [notifyContext] (caller) are the same. + */ + bool compareNotifyContext(Object object); + /** + * Notify the interested object. + * + * - Param [note] - the [INotification] to pass to the caller's [notifyMethod]. + */ + void notifyObserver(INotification note); } - diff --git a/lib/src/interfaces/IProxy.dart b/lib/src/interfaces/IProxy.dart index 55a5a3e..2a1f3b9 100644 --- a/lib/src/interfaces/IProxy.dart +++ b/lib/src/interfaces/IProxy.dart @@ -17,50 +17,47 @@ part of puremvc; * * See [IModel] */ -abstract class IProxy extends INotifier -{ - /** +abstract class IProxy extends INotifier { + /** * Get the [IProxy] [name]. * * - Returns [String] - the [IProxy] instance [name]. */ - String getName(); + String getName(); - /** + /** * Set the [dataObject]. * * - Param [Dynamic] - the [dataObject] this [IProxy] will tend. */ - void setData( dynamic dataObject ); + void setData(dynamic dataObject); - /** + /** * Get the [dataObject]. * * - Returns [Dynamic] - the [dataObject]. */ - dynamic getData(); + dynamic getData(); - /** + /** * Called by the [IModel] when the [IProxy] is registered. */ - void onRegister( ); + void onRegister(); - /** + /** * Called by the [IModel] when the [IProxy] is removed. */ - void onRemove( ); + void onRemove(); - /** + /** * This [IProxy]'s [dataObject]. */ - void set data( dynamic dataObject ); - dynamic get data; + void set data(dynamic dataObject); + dynamic get data; - /** + /** * This [IProxy]'s [name]. */ - void set name( String proxyName ); - String get name; - - + void set name(String proxyName); + String get name; } diff --git a/lib/src/interfaces/IView.dart b/lib/src/interfaces/IView.dart index 041d23c..c624e37 100644 --- a/lib/src/interfaces/IView.dart +++ b/lib/src/interfaces/IView.dart @@ -14,15 +14,14 @@ part of puremvc; * * See [IMediator], [IObserver], [INotification] */ -abstract class IView -{ +abstract class IView { /** * Register an [IObserver] to be notified of [INotification]s with a given name. * * - Param [noteName] - the name of the [INotification] to notify this [IObserver] of. * - Param [observer] - the [IObserver] to register. */ - void registerObserver( String noteName, IObserver observer); + void registerObserver(String noteName, IObserver observer); /** * Remove an [IObserver] from the list for a given [INotification] name. @@ -30,7 +29,7 @@ abstract class IView * - Param [noteName] - which [IObserver] list to remove from. * - Param [notifyContext] - remove [IObserver]s with this object as the [notifyContext]. */ - void removeObserver( String noteName, Object notifyContext ); + void removeObserver(String noteName, Object notifyContext); /** * Notify the [IObserver]s for a particular [INotification]. @@ -41,7 +40,7 @@ abstract class IView * * - Param [note] - the [INotification] to notify [IObservers] of. */ - void notifyObservers( INotification note ); + void notifyObservers(INotification note); /** * Register an [IMediator] instance with the [IView]. @@ -57,7 +56,7 @@ abstract class IView * * - Param [mediator] - a reference to the [IMediator] instance. */ - void registerMediator( IMediator mediator ); + void registerMediator(IMediator mediator); /** * Retrieve an [IMediator] from the [IView]. @@ -65,7 +64,7 @@ abstract class IView * - Param [mediatorName] - the name of the [IMediator] instance to retrieve. * - Returns [IMediator] - the [IMediator] instance previously registered in this core with the given [mediatorName]. */ - IMediator retrieveMediator( String mediatorName ); + IMediator retrieveMediator(String mediatorName); /** * Remove an [IMediator] from the [IView]. @@ -73,7 +72,7 @@ abstract class IView * - Param [mediatorName] - name of the [IMediator] instance to be removed. * - Returns [IMediator] - the [IMediator] that was removed from this core's [IView]. */ - IMediator removeMediator( String mediatorName ); + IMediator removeMediator(String mediatorName); /** * Check if an [IMediator] is registered with the [IView]. @@ -81,13 +80,10 @@ abstract class IView * - Param [mediatorName] - the name of the [IMediator] you're looking for. * - Returns [bool] - whether an [IMediator] is registered in this core with the given [mediatorName]. */ - bool hasMediator( String mediatorName ); + bool hasMediator(String mediatorName); /** * This [IView]'s Multiton key */ - void set multitonKey( String key ); String get multitonKey; - } - diff --git a/lib/src/patterns/command/MacroCommand.dart b/lib/src/patterns/command/MacroCommand.dart index fe13835..2493900 100644 --- a/lib/src/patterns/command/MacroCommand.dart +++ b/lib/src/patterns/command/MacroCommand.dart @@ -13,8 +13,7 @@ part of puremvc; * * See [ICommand], [IController], [INotification], [SimpleCommand], [INotifier] */ -class MacroCommand extends Notifier implements ICommand -{ +class MacroCommand extends Notifier implements ICommand { /** * Constructor. * @@ -22,9 +21,8 @@ class MacroCommand extends Notifier implements ICommand * instead, override the [initializeMacroCommand] * method. */ - MacroCommand() - { - subCommands = new List(); + MacroCommand() { + subCommands = List.empty(growable: true); initializeMacroCommand(); } @@ -36,7 +34,7 @@ class MacroCommand extends Notifier implements ICommand * * Note that 'SubCommand's may be any [ICommand] implementor, [MacroCommand]s or [SimpleCommands] are both acceptable. */ - void initializeMacroCommand(){} + void initializeMacroCommand() {} /** * Add a 'SubCommand'. @@ -45,9 +43,8 @@ class MacroCommand extends Notifier implements ICommand * * - Param [commandFactory] - a Function that constructs an instance of an [ICommand]. */ - void addSubCommand( Function commandFactory ) - { - subCommands.add( commandFactory ); + void addSubCommand(Function commandFactory) { + subCommands.add(commandFactory); } /** @@ -57,15 +54,14 @@ class MacroCommand extends Notifier implements ICommand * * - Param [note] - the [INotification] object to be passed to each 'SubCommand'. */ - void execute( INotification note ) - { - for ( Function commandFactory in subCommands ) { - ICommand commandInstance = commandFactory(); - commandInstance.initializeNotifier( multitonKey ); - commandInstance.execute( note ); - } + void execute(INotification note) { + for (Function commandFactory in subCommands) { + ICommand commandInstance = commandFactory(); + commandInstance.initializeNotifier(_multitonKey); + commandInstance.execute(note); + } } // This [MacroCommand]'s 'SubCommands' - List subCommands; + late List subCommands; } diff --git a/lib/src/patterns/command/SimpleCommand.dart b/lib/src/patterns/command/SimpleCommand.dart index 882118a..ff119c7 100644 --- a/lib/src/patterns/command/SimpleCommand.dart +++ b/lib/src/patterns/command/SimpleCommand.dart @@ -7,9 +7,7 @@ part of puremvc; * * See [ICommand], [IController], [INotification], [MacroCommand], [INotifier] */ -class SimpleCommand extends Notifier implements ICommand -{ - +class SimpleCommand extends Notifier implements ICommand { /** * Respond to the [INotification] that triggered this [SimpleCommand]. * @@ -17,6 +15,5 @@ class SimpleCommand extends Notifier implements ICommand * * - Param [note] - an [INotification] object that triggered the execution of this [SimpleCommand] */ - void execute( INotification note ){ } - -} \ No newline at end of file + void execute(INotification note) {} +} diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index 4848ea4..a83a4ac 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -22,8 +22,7 @@ part of puremvc; * * See [Model], [View], [Controller], [INotification], [ICommand], [IMediator], [IProxy] */ -class Facade implements IFacade -{ +class Facade implements IFacade { /** * Constructor. * @@ -32,11 +31,11 @@ class Facade implements IFacade * * - Throws [MultitonErrorFacadeExists] if instance for this Multiton key has already been constructed. */ - Facade( String key ) - { - if ( instanceMap[ key ] != null ) throw new MultitonErrorFacadeExists(); - initializeNotifier( key ); - instanceMap[ multitonKey ] = this; + Facade(String key) { + if (instanceMap.containsKey(key)) throw MultitonErrorFacadeExists(); + _multitonKey = key; + initializeNotifier(key); + instanceMap[_multitonKey!] = this; initializeFacade(); } @@ -47,8 +46,7 @@ class Facade implements IFacade * subclass to do any subclass specific initializations. Be * sure to call [super.initializeFacade()], though. */ - void initializeFacade( ) - { + void initializeFacade() { initializeModel(); initializeController(); initializeView(); @@ -59,12 +57,13 @@ class Facade implements IFacade * * - Returns the [IFacade] Multiton instance for the specified key. */ - static IFacade getInstance( String key ) - { - if ( key == null || key == "" ) return null; - if ( instanceMap == null ) instanceMap = new Map(); - if ( instanceMap[ key ] == null ) instanceMap[ key ] = new Facade( key ); - return instanceMap[ key ]; + static IFacade? getInstance(String? key) { + if (key == null || key == "") return null; + if (instanceMap.containsKey(key)) { + return instanceMap[key]; + } else { + return instanceMap[key] = new Facade(key); + } } /** @@ -74,10 +73,9 @@ class Facade implements IFacade * * Override this method in a subclass of [Facade] if you want to provide a different [IController]. */ - void initializeController( ) - { - if ( controller != null ) return; - controller = Controller.getInstance( multitonKey ); + void initializeController() { + if (controller != null) return; + controller = Controller.getInstance(_multitonKey)!; } /** @@ -87,13 +85,11 @@ class Facade implements IFacade * * Override this method in a subclass of [Facade] if you wish to initialize a different [IModel]. */ - void initializeModel( ) - { - if ( model != null ) return; - model = Model.getInstance( multitonKey ); + void initializeModel() { + if (model != null) return; + model = Model.getInstance(_multitonKey)!; } - /** * Initialize the [IView]. * @@ -101,10 +97,9 @@ class Facade implements IFacade * * Override this method in a subclass of [Facade] if you wish to initialize a different [IView]. */ - void initializeView( ) - { - if ( view != null ) return; - view = View.getInstance( multitonKey ); + void initializeView() { + if (view != null) return; + view = View.getInstance(_multitonKey!); } /** @@ -113,9 +108,12 @@ class Facade implements IFacade * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ - void registerCommand( String noteName, Function commandFactory ) - { - controller.registerCommand( noteName, commandFactory ); + void registerCommand(String noteName, Function commandFactory) { + controller!.registerCommand(noteName, commandFactory); + } + + void executeCommand(String name, [dynamic body = null, String? type]) { + controller!.executeCommand(new Notification(name, body, type)); } /** @@ -123,9 +121,8 @@ class Facade implements IFacade * * - Param [noteName] - the name of the [INotification] to remove the [ICommand] mapping for */ - void removeCommand( String noteName ) - { - controller.removeCommand( noteName ); + void removeCommand(String noteName) { + controller!.removeCommand(noteName); } /** @@ -134,9 +131,8 @@ class Facade implements IFacade * - Param [noteName] - the name of the [INotification]. * - Returns [bool] - whether an [ICommand] is currently registered for the given [noteName]. */ - bool hasCommand( String noteName ) - { - return controller.hasCommand( noteName ); + bool hasCommand(String noteName) { + return controller!.hasCommand(noteName); } /** @@ -144,9 +140,8 @@ class Facade implements IFacade * * - Param [proxy] - an object reference to be held by the [IModel]. */ - void registerProxy( IProxy proxy ) - { - model.registerProxy( proxy ); + void registerProxy(IProxy proxy) { + model!.registerProxy(proxy); } /** @@ -155,9 +150,8 @@ class Facade implements IFacade * - Param [proxyName] - the name of the [IProxy] instance to retrieve. * - Returns the [IProxy] instance previously registered with the given [proxyName]. */ - IProxy retrieveProxy( String proxyName ) - { - return model.retrieveProxy( proxyName ); + IProxy retrieveProxy(String proxyName) { + return model!.retrieveProxy(proxyName); } /** @@ -166,10 +160,9 @@ class Facade implements IFacade * - Param [proxyName] - name of the [IProxy] instance to be removed. * - Returns [IProxy] - the [IProxy] that was removed from the [IModel]. */ - IProxy removeProxy( String proxyName ) - { - IProxy proxy; - if ( model != null ) proxy = model.removeProxy ( proxyName ); + IProxy? removeProxy(String proxyName) { + IProxy? proxy; + if (model != null) proxy = model!.removeProxy(proxyName); return proxy; } @@ -179,9 +172,8 @@ class Facade implements IFacade * - Param [proxyName] - the name of the [IProxy] instance you're looking for. * - Returns [bool] - whether an [IProxy] is currently registered with the given [proxyName]. */ - bool hasProxy( String proxyName ) - { - return model.hasProxy( proxyName ); + bool hasProxy(String proxyName) { + return model!.hasProxy(proxyName); } /** @@ -198,9 +190,8 @@ class Facade implements IFacade * * - Param [mediator] - a reference to the [IMediator] instance. */ - void registerMediator( IMediator mediator ) - { - if ( view != null ) view.registerMediator( mediator ); + void registerMediator(IMediator mediator) { + if (view != null) view!.registerMediator(mediator); } /** @@ -209,9 +200,8 @@ class Facade implements IFacade * - Param [mediatorName] - the name of the [IMediator] instance to retrieve. * - Returns [IMediator] - the [IMediator] instance previously registered in this core with the given [mediatorName]. */ - IMediator retrieveMediator( String mediatorName ) - { - return view.retrieveMediator( mediatorName ); + IMediator retrieveMediator(String mediatorName) { + return view!.retrieveMediator(mediatorName); } /** @@ -220,10 +210,9 @@ class Facade implements IFacade * - Param [mediatorName] - name of the [IMediator] instance to be removed. * - Returns [IMediator] - the [IMediator] that was removed from this core's [IView]. */ - IMediator removeMediator( String mediatorName ) - { - IMediator mediator; - if ( view != null ) mediator = view.removeMediator( mediatorName ); + IMediator? removeMediator(String mediatorName) { + IMediator? mediator; + if (view != null) mediator = view!.removeMediator(mediatorName); return mediator; } @@ -233,9 +222,8 @@ class Facade implements IFacade * Param [mediatorName] * Returns [bool] - whether an [IMediator] is registered in this core with the given [mediatorName]. */ - bool hasMediator( String mediatorName ) - { - return view.hasMediator( mediatorName ); + bool hasMediator(String mediatorName) { + return view!.hasMediator(mediatorName); } /** @@ -248,9 +236,8 @@ class Facade implements IFacade * - Param [body] - the body of the note (optional) * - Param [type] - the type of the note (optional) */ - void sendNotification( String noteName, [dynamic body, String type] ) - { - notifyObservers( new Notification( noteName, body, type ) ); + void sendNotification(String noteName, [dynamic body, String? type]) { + notifyObservers(new Notification(noteName, body, type)); } /** @@ -259,9 +246,8 @@ class Facade implements IFacade * - Param [noteName] - the name of the [INotification] to notify this [IObserver] of. * - Param [observer] - the [IObserver] to register. */ - void registerObserver( String noteName, IObserver observer ) - { - view.registerObserver(noteName, observer); + void registerObserver(String noteName, IObserver observer) { + view!.registerObserver(noteName, observer); } /** @@ -270,9 +256,8 @@ class Facade implements IFacade * - Param [noteName] - which [IObserver] list to remove from. * - Param [notifyContext] - remove [IObserver]s with this object as the [notifyContext]. */ - void removeObserver( String noteName, Object notifyContext ) - { - view.removeObserver( noteName, notifyContext ); + void removeObserver(String noteName, Object notifyContext) { + view!.removeObserver(noteName, notifyContext); } /** @@ -285,25 +270,21 @@ class Facade implements IFacade * * - Param [note] the [INotification] to have the [View] notify [Observers] of. */ - void notifyObservers( INotification note ) - { - if ( view != null ) view.notifyObservers( note ); + void notifyObservers(INotification note) { + if (view != null) view!.notifyObservers(note); } /** * Initialize this [INotifier]. * - * This is how an [INotifier] gets its [multitonKey]. + * This is how an [INotifier] gets its [_multitonKey]. * Calls to [sendNotification] or to access the * [facade] will fail until after this method * has been called. * - * - Param [key] - the [multitonKey] for this [INotifier] to use. + * - Param [key] - the [_multitonKey] for this [INotifier] to use. */ - void initializeNotifier( String key ) - { - multitonKey = key; - } + void initializeNotifier(String? key) {} /** * Check if a Core is registered or not. @@ -311,9 +292,8 @@ class Facade implements IFacade * - Param [key] - the Multiton key for the Core. * - Returns [bool] - whether a Core is registered with the given [key]. */ - static bool hasCore( String key ) - { - return ( instanceMap[ key ] != null ); + static bool hasCore(String key) { + return instanceMap.containsKey(key); } /** @@ -324,32 +304,31 @@ class Facade implements IFacade * * - Param [key] - the Multiton key of the Core to remove. */ - static void removeCore( String key ) - { - if ( instanceMap[ key ] == null ) return; - Model.removeModel( key ); - View.removeView( key ); - Controller.removeController( key ); - instanceMap[ key ] = null; + static void removeCore(String key) { + if (!instanceMap.containsKey(key)) return; + Model.removeModel(key); + View.removeView(key); + Controller.removeController(key); + instanceMap.remove(key); } // References to [IModel], [IView], and [IController] - IController controller; - IModel model; - IView view; + IController? controller; + IModel? model; + IView? view; // This [IFacade]'s Multiton key - String multitonKey; + String? _multitonKey; + String? get multitonKey => _multitonKey; // The [IFacade] Multiton instanceMap. - static Map instanceMap; + static Map instanceMap = Map(); } class MultitonErrorFacadeExists { - const MultitonErrorFacadeExists (); + const MultitonErrorFacadeExists(); String toString() { return "IFacade Multiton instance already constructed for this key."; } } - diff --git a/lib/src/patterns/mediator/Mediator.dart b/lib/src/patterns/mediator/Mediator.dart index 1c6e214..48c66c0 100644 --- a/lib/src/patterns/mediator/Mediator.dart +++ b/lib/src/patterns/mediator/Mediator.dart @@ -23,24 +23,21 @@ part of puremvc; * * See [INotification], [IView] */ -class Mediator extends Notifier implements IMediator -{ - +class Mediator extends Notifier implements IMediator { /** * Constructor * * - Param [name] - the [name] this [IMediator] will be registered with. * - Param [viewComponent] - the View Component (optional) */ - Mediator( String this.name, [dynamic this.viewComponent] ){ } + Mediator(String this.name, [dynamic this.viewComponent]) {} /** * Get the [IMediator] instance's [name]. * * - Returns [String] - the [IMediator] instance's [name]. */ - String getName() - { + String getName() { return name; } @@ -49,8 +46,7 @@ class Mediator extends Notifier implements IMediator * * - Param [Dynamic] - the [viewComponent]. */ - void setViewComponent( dynamic component ) - { + void setViewComponent(dynamic component) { viewComponent = component; } @@ -59,8 +55,7 @@ class Mediator extends Notifier implements IMediator * * - Returns [Dynamic] - the View Component */ - dynamic getViewComponent() - { + dynamic getViewComponent() { return viewComponent; } @@ -69,9 +64,8 @@ class Mediator extends Notifier implements IMediator * * - Returns [List] - a [List] of the [INotification] names this [IMediator] has an interest in. */ - List listNotificationInterests( ) - { - return new List(); + List listNotificationInterests() { + return List.empty(growable: true); } /** @@ -79,17 +73,17 @@ class Mediator extends Notifier implements IMediator * * - Param [note] - the [INotification] to be handled. */ - void handleNotification( INotification note ) {} + void handleNotification(INotification note) {} /** * Called by the [IView] when the [IMediator] is registered. */ - void onRegister( ) {} + void onRegister() {} /** * Called by the [IView] when the [IMediator] is removed. */ - void onRemove( ) {} + void onRemove() {} /** * This [IMediator]'s [name]. diff --git a/lib/src/patterns/observer/Notification.dart b/lib/src/patterns/observer/Notification.dart index 857a1c4..d0f8a77 100644 --- a/lib/src/patterns/observer/Notification.dart +++ b/lib/src/patterns/observer/Notification.dart @@ -19,80 +19,73 @@ part of puremvc; * * See [IView], [IObserver], [Notification] */ -class Notification implements INotification -{ - /** - * Constructor. - * - * - Param [name] - name of the [INotification]. - * - Param [body] - the [INotification] body. (optional) - * - Param [type] - the type of the [INotification] (optional) - */ - Notification( String this.name, [dynamic this.body, String this.type] ){} +class Notification implements INotification { + /** + * Constructor. + * + * - Param [_name] - name of the [INotification]. + * - Param [_body] - the [INotification] body. (optional) + * - Param [_type] - the type of the [INotification] (optional) + */ + Notification(this._name, [dynamic this._body, this._type]) {} - /** - * Get the [name] of the [INotification]. - * - * - Returns [String] - the name of the [INotification]. - */ - String getName() - { - return name; - } + /** + * Get the [name] of the [INotification]. + * + * - Returns [String] - the name of the [INotification]. + */ + String getName() { + return _name; + } - /** - * Set the [body] of the [INotification]. - * - * - Param [body] - the body of the [INotification]. - */ - void setBody( dynamic bodyObject ) - { - body = bodyObject; - } + /** + * Set the [body] of the [INotification]. + * + * - Param [body] - the body of the [INotification]. + */ + void setBody(dynamic bodyObject) { + _body = bodyObject; + } - /** - * Get the [body] of the [INotification]. - * - * - Returns [Dynamic] - the body of the [INotification]. - */ - dynamic getBody() - { - return body; - } + /** + * Get the [body] of the [INotification]. + * + * - Returns [Dynamic] - the body of the [INotification]. + */ + dynamic getBody() { + return _body; + } - /** - * Set the [type] of the [INotification]. - * - * - Param [type] - the type of the [INotification]. - */ - void setType( String noteType ) - { - type = noteType; - } + /** + * Set the [type] of the [INotification]. + * + * - Param [type] - the type of the [INotification]. + */ + void setType(String? noteType) { + _type = noteType; + } - /** - * Get the [type] of the [INotification]. - * - * - Returns [String] - the type of the [INotification]. - */ - String getType() - { - return type; - } + /** + * Get the [type] of the [INotification]. + * + * - Returns [String] - the type of the [INotification]. + */ + String? getType() { + return _type; + } - /** - * This [INotifications]'s [name] - */ - String name; + /** + * This [INotifications]'s [name] + */ + final String _name; - /** - * This [INotifications]'s [type] - */ - String type; - - /** - * This [INotifications]'s [body] - */ - dynamic body; + /** + * This [INotifications]'s [type] + */ + String? _type; + /** + * This [INotifications]'s [body] + */ + dynamic _body; } diff --git a/lib/src/patterns/observer/Notifier.dart b/lib/src/patterns/observer/Notifier.dart index e9dfd3a..ad17d91 100644 --- a/lib/src/patterns/observer/Notifier.dart +++ b/lib/src/patterns/observer/Notifier.dart @@ -28,57 +28,51 @@ part of puremvc; * * See [Proxy], [Facade], [Mediator], [MacroCommand], [SimpleCommand] */ -class Notifier implements INotifier -{ +class Notifier implements INotifier { + Notifier() {} - Notifier(){ - - } - - /** - * Send an [INotification]. - * - * Convenience method to prevent having to construct new - * [INotification] instances in our implementation code. - * - * - Param [noteName] the name of the note to send - * - Param [body] - the body of the note (optional) - * - Param [type] - the type of the note (optional) - */ - void sendNotification( String noteName, [dynamic body, String type] ) - { - if (facade != null) { - facade.sendNotification( noteName, body, type ); - } + /** + * Send an [INotification]. + * + * Convenience method to prevent having to construct new + * [INotification] instances in our implementation code. + * + * - Param [noteName] the name of the note to send + * - Param [body] - the body of the note (optional) + * - Param [type] - the type of the note (optional) + */ + void sendNotification(String noteName, [dynamic body, String? type]) { + if (facade != null) { + facade.sendNotification(noteName, body, type); } + } - /** - * Initialize this [INotifier] instance. - * - * This is how a [INotifier] gets its [multitonKey]. - * Calls to [sendNotification] or access to the - * [facade] will fail until after this method - * has been called. - * - * - Param [key] - the Multiton key for this [INotifier]. - */ - void initializeNotifier( String key ) - { - multitonKey = key; - } + /** + * Initialize this [INotifier] instance. + * + * This is how a [INotifier] gets its [_multitonKey]. + * Calls to [sendNotification] or access to the + * [facade] will fail until after this method + * has been called. + * + * - Param [key] - the Multiton key for this [INotifier]. + */ + void initializeNotifier(String? key) { + _multitonKey = key; + } - /** - * Return the Multiton Facade instance - * - Throws [MultitonErrorNotifierLacksKey] if no multitonKey is set. Usually means facade getter is being accessed before initializeNotifier has been called (i.e., from the constructor). Defer facade access until the onRegister method. - */ - IFacade get facade - { - if ( multitonKey == null ) throw new MultitonErrorNotifierLacksKey( ); - return Facade.getInstance( multitonKey ); - } + /** + * Return the Multiton Facade instance + * - Throws [MultitonErrorNotifierLacksKey] if no multitonKey is set. Usually means facade getter is being accessed before initializeNotifier has been called (i.e., from the constructor). Defer facade access until the onRegister method. + */ + IFacade get facade { + if (_multitonKey == null) throw MultitonErrorNotifierLacksKey(); + return Facade.getInstance(_multitonKey!)!; + } - // The Multiton Key for this app - String multitonKey; + // The Multiton Key for this app + String? _multitonKey; + String? get multitonKey => _multitonKey; } class MultitonErrorNotifierLacksKey { @@ -87,4 +81,4 @@ class MultitonErrorNotifierLacksKey { String toString() { return "multitonKey for this Notifier not yet initialized!"; } -} \ No newline at end of file +} diff --git a/lib/src/patterns/observer/Observer.dart b/lib/src/patterns/observer/Observer.dart index 24cbefb..fea04e9 100644 --- a/lib/src/patterns/observer/Observer.dart +++ b/lib/src/patterns/observer/Observer.dart @@ -25,18 +25,16 @@ part of puremvc; * * See [IView], [INotification] */ -class Observer implements IObserver -{ - +class Observer implements IObserver { /** * This [IObserver]'s [notifyMethod] (i.e., callback) */ - Function notifyMethod; + Function? _notifyMethod; /** * This [IObserver]'s [notifyContext] (i.e., caller) */ - Object notifyContext; + Object? _notifyContext; /** * Constructor. @@ -47,7 +45,7 @@ class Observer implements IObserver * Param [notifyMethod] the callback method * Param [notifyContext] the caller object */ - Observer( Function this.notifyMethod, [Object this.notifyContext] ){} + Observer([this._notifyMethod, this._notifyContext]) {} /** * Set the notification method. @@ -56,9 +54,8 @@ class Observer implements IObserver * * - Param [notifyMethod] - the notification (callback) method of the interested object. */ - void setNotifyMethod( Function callback ) - { - notifyMethod = callback; + void setNotifyMethod(Function? callback) { + _notifyMethod = callback; } /** @@ -66,9 +63,8 @@ class Observer implements IObserver * * - Param [caller] - a reference to the object to be notified. */ - void setNotifyContext( Object caller ) - { - notifyContext = caller; + void setNotifyContext(Object? caller) { + _notifyContext = caller; } /** @@ -76,29 +72,22 @@ class Observer implements IObserver * * - Returns [Function] - the notification (callback) method of the interested object. */ - Function getNotifyMethod() - { - return notifyMethod; - } + Function? getNotifyMethod() => _notifyMethod; /** * Get the notification context. * * - Returns [Object] - the caller. */ - Object getNotifyContext() - { - return notifyContext; - } + Object? getNotifyContext() => _notifyContext; /** * Notify the interested object. * * - Param [note] - the [INotification] to pass to the caller's [notifyMethod]. */ - void notifyObserver( INotification notification ) - { - if ( notifyContext != null ) getNotifyMethod()( notification ); + void notifyObserver(INotification notification) { + if (_notifyContext != null) getNotifyMethod()!(notification); } /** @@ -107,8 +96,11 @@ class Observer implements IObserver * - Param [Object] - the object to compare. * - Returns [bool] - whether the given object and the [notifyContext] (caller) are the same. */ - bool compareNotifyContext( Object object ) - { - return identical(object, notifyContext); + bool compareNotifyContext(Object object) { + return identical(object, _notifyContext); + } + + set notifyContext(Object? caller) { + notifyContext = caller; } } diff --git a/lib/src/patterns/proxy/Proxy.dart b/lib/src/patterns/proxy/Proxy.dart index f28ee5f..ba91504 100644 --- a/lib/src/patterns/proxy/Proxy.dart +++ b/lib/src/patterns/proxy/Proxy.dart @@ -17,66 +17,61 @@ part of puremvc; * * See [IModel] */ -class Proxy extends Notifier implements IProxy -{ - /** +class Proxy extends Notifier implements IProxy { + /** * Constructor * * - Param [name] - the [name] this [IProxy] will be registered with. * - Param [data] - the Data Object (optional) */ - Proxy( String this.name, [dynamic this.data] ){ } + Proxy(String this.name, [dynamic this.data]) {} - /** + /** * Get the [IProxy] [name]. * * - Returns [String] - the [IProxy] instance [name]. */ - String getName() - { - return name; - } + String getName() { + return name; + } - /** + /** * Set the [dataObject]. * * - Param [Dynamic] - the [dataObject] this [IProxy] will tend. */ - void setData( dynamic dataObject ) - { - data = dataObject; - } + void setData(dynamic dataObject) { + data = dataObject; + } - /** + /** * Get the [dataObject]. * * - Returns [Dynamic] - the [dataObject]. */ - dynamic getData() - { - return data; - } + dynamic getData() { + return data; + } - /** + /** * Called by the [IModel] when the [IProxy] is registered. * * Override in your subclass and add code to be run at registration time. */ - void onRegister(){} + void onRegister() {} - /** + /** * Called by the [IModel] when the [IProxy] is removed */ - void onRemove(){} + void onRemove() {} - /** + /** * This [IProxy]'s [name]. */ - String name; + String name; - /** + /** * This [IProxy]'s [dataObject]. */ - dynamic data; - + dynamic data; } diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..2b5bfdd --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,557 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "58826e40314219b223f4723dd4205845040161cdc2df3e6a1cdceed5d8165084" + url: "https://pub.dev" + source: hosted + version: "63.0.0" + analyzer: + dependency: "direct main" + description: + name: analyzer + sha256: f85566ec7b3d25cbea60f7dd4f157c5025f2f19233ca4feeed33b616c78a26a3 + url: "https://pub.dev" + source: hosted + version: "6.1.0" + archive: + dependency: transitive + description: + name: archive + sha256: "0c8368c9b3f0abbc193b9d6133649a614204b528982bebc7026372d61677ce3a" + url: "https://pub.dev" + source: hosted + version: "3.3.7" + args: + dependency: transitive + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + bazel_worker: + dependency: transitive + description: + name: bazel_worker + sha256: "6aa1de567844e1a1db3ac16959159b31a71128fdd27d63d861ad5aa7299e48c5" + url: "https://pub.dev" + source: hosted + version: "1.0.3" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "5f02d73eb2ba16483e693f80bee4f088563a820e47d1027d4cdfe62b5bb43e65" + url: "https://pub.dev" + source: hosted + version: "4.0.0" + build_modules: + dependency: transitive + description: + name: build_modules + sha256: "14a8e9bf4b1ae3f5d6c925c1386da59e818c68cc6f1f6fda991f7c6b74c6ebb9" + url: "https://pub.dev" + source: hosted + version: "5.0.4" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "6c4dd11d05d056e76320b828a1db0fc01ccd376922526f8e9d6c796a5adbac20" + url: "https://pub.dev" + source: hosted + version: "2.2.1" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "10c6bcdbf9d049a0b666702cf1cee4ddfdc38f02a19d35ae392863b47519848b" + url: "https://pub.dev" + source: hosted + version: "2.4.6" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "6d6ee4276b1c5f34f21fdf39425202712d2be82019983d52f351c94aafbc2c41" + url: "https://pub.dev" + source: hosted + version: "7.2.10" + build_web_compilers: + dependency: "direct dev" + description: + name: build_web_compilers + sha256: "49270bd113959ac061512d2bdf0046cf97395b88b04a6baed2b9b276c88559ec" + url: "https://pub.dev" + source: hosted + version: "4.0.5" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" + url: "https://pub.dev" + source: hosted + version: "8.6.1" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: "4ad01d6e56db961d29661561effde45e519939fdaeb46c351275b182eac70189" + url: "https://pub.dev" + source: hosted + version: "4.5.0" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" + url: "https://pub.dev" + source: hosted + version: "1.6.3" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + url: "https://pub.dev" + source: hosted + version: "4.8.1" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" + source: hosted + version: "0.12.16" + meta: + dependency: transitive + description: + name: meta + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + mime: + dependency: transitive + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" + source: hosted + version: "1.8.3" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" + url: "https://pub.dev" + source: hosted + version: "3.7.3" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + protobuf: + dependency: transitive + description: + name: protobuf + sha256: "4034a02b7e231e7e60bff30a8ac13a7347abfdac0798595fae0b90a3f0afe759" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 + url: "https://pub.dev" + source: hosted + version: "1.2.3" + scratch_space: + dependency: transitive + description: + name: scratch_space + sha256: "8510fbff458d733a58fc427057d1ac86303b376d609d6e1bc43f240aad9aa445" + url: "https://pub.dev" + source: hosted + version: "1.0.2" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e + url: "https://pub.dev" + source: hosted + version: "1.1.2" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" + url: "https://pub.dev" + source: hosted + version: "0.10.12" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: b9a384c4b9c4966dbf7215e7c033a78db1da7e5dcaf8da9232c5f24735f65652 + url: "https://pub.dev" + source: hosted + version: "1.24.5" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + test_core: + dependency: transitive + description: + name: test_core + sha256: c6a536288535efef8526eea8adfa4e25fdd2849fa7f457ecb2a52099998ce8f7 + url: "https://pub.dev" + source: hosted + version: "0.5.5" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "0fae432c85c4ea880b33b497d32824b97795b04cdaa74d270219572a1f50268d" + url: "https://pub.dev" + source: hosted + version: "11.9.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.0.0 <3.3.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0ea27e6..2d4c8cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,9 +4,10 @@ author: Cliff Hall description: PureMVC is a lightweight framework for creating applications based upon the classic Model-View-Controller design meta-pattern. It supports modular programming through the use of Multiton Core actors. homepage: http://www.puremvc.org environment: - sdk: '>=0.8.10+6 <2.0.0' + sdk: '^3.0.0' dependencies: - analyzer: '>=0.10.1 <0.11.0' - browser: '>=0.9.0 <0.10.0' + analyzer: '^6.0.0' dev_dependencies: - unittest: '>=0.9.0 <0.10.0' + build_runner: any + build_web_compilers: any + test: ^1.24.5 diff --git a/test/Test_Controller.dart b/test/Test_Controller.dart index ca5eb42..4744e34 100644 --- a/test/Test_Controller.dart +++ b/test/Test_Controller.dart @@ -1,100 +1,95 @@ part of puremvc_unit_tests; -class Test_Controller -{ - _tests() - { - group('Controller', () - { +class Test_Controller { + _tests() { + group('Controller', () { test('getInstance()', () { // Get a unique multiton instance of Controller String multitonKey = "ControllerTest1"; - mvc.IController controller = mvc.Controller.getInstance( multitonKey ); + final controller = mvc.Controller.getInstance(multitonKey) as mvc.IController; // Make sure a Controller instance was returned - expect( controller, isNotNull ); + expect(controller, isNotNull); // Call getInstance() again - mvc.IController again = mvc.Controller.getInstance( multitonKey ); + final again = mvc.Controller.getInstance(multitonKey) as mvc.IController; // Make sure the same Controller instance was returned - expect( controller, same(again) ); + expect(controller, same(again)); }); test('registerCommand(), hasCommand()', () { // Get a unique multiton instance of Controller String multitonKey = "ControllerTest2"; - mvc.IController controller = mvc.Controller.getInstance( multitonKey ); + final controller = mvc.Controller.getInstance(multitonKey) as mvc.IController; // Register a Command String noteName = "ControllerTest2Note"; - controller.registerCommand( noteName, () => new ControllerTestMacroCommand() ); + controller.registerCommand(noteName, () => new ControllerTestMacroCommand()); // Make sure it's registered - expect( controller.hasCommand( noteName ), isTrue ); + expect(controller.hasCommand(noteName), isTrue); }); test('executeCommand() +SimpleCommand', () { // Get a unique multiton instance of Controller String multitonKey = "ControllerTest3"; - mvc.IController controller = mvc.Controller.getInstance( multitonKey ); + final controller = mvc.Controller.getInstance(multitonKey) as mvc.IController; // Register a Command String noteName = "ControllerTest3Note"; - controller.registerCommand( noteName, () => new ControllerTestDoubleInputCommand() ); + controller.registerCommand(noteName, () => new ControllerTestDoubleInputCommand()); // Create a Notification - ControllerTestVO vo = new ControllerTestVO( 5 ); - mvc.INotification note = new mvc.Notification( noteName, vo ); + ControllerTestVO vo = new ControllerTestVO(5); + mvc.INotification note = new mvc.Notification(noteName, vo); // Have the Controller execute the Command - controller.executeCommand( note ); + controller.executeCommand(note); // Make sure the Command executed - expect( vo.doubled, equals(10) ); - expect( vo.squared, equals(null) ); - + expect(vo.doubled, equals(10)); + expect(vo.squared, equals(null)); }); test('executeCommand() +MacroCommand', () { // Get a unique multiton instance of Controller String multitonKey = "ControllerTest4"; - mvc.IController controller = mvc.Controller.getInstance( multitonKey ); + final controller = mvc.Controller.getInstance(multitonKey) as mvc.IController; // Register a Command String noteName = "ControllerTest4Note"; - controller.registerCommand( noteName, () => new ControllerTestMacroCommand() ); + controller.registerCommand(noteName, () => new ControllerTestMacroCommand()); // Create a Notification - ControllerTestVO vo = new ControllerTestVO( 5 ); - mvc.INotification note = new mvc.Notification( noteName, vo ); + ControllerTestVO vo = new ControllerTestVO(5); + mvc.INotification note = new mvc.Notification(noteName, vo); // Have the Controller execute the Command - controller.executeCommand( note ); + controller.executeCommand(note); // Make sure the Command executed - expect( vo.doubled, equals(10) ); - expect( vo.squared, equals(25) ); - + expect(vo.doubled, equals(10)); + expect(vo.squared, equals(25)); }); test('removeCommand()', () { // Get a unique multiton instance of Controller String multitonKey = "ControllerTest5"; - mvc.IController controller = mvc.Controller.getInstance( multitonKey ); + final controller = mvc.Controller.getInstance(multitonKey) as mvc.IController; // Register a Command String noteName = "ControllerTest5Note"; - controller.registerCommand( noteName, () => new ControllerTestMacroCommand() ); + controller.registerCommand(noteName, () => new ControllerTestMacroCommand()); // Make sure it's registered - expect( controller.hasCommand( noteName ), isTrue ); + expect(controller.hasCommand(noteName), isTrue); // Remove the Command - controller.removeCommand( noteName ); + controller.removeCommand(noteName); // Make sur the Controller doesn't know about it any more - expect( controller.hasCommand( noteName ), isFalse ); + expect(controller.hasCommand(noteName), isFalse); }); }); } @@ -104,29 +99,24 @@ class Test_Controller } } -class ControllerTestVO -{ - int input; - int doubled; - int squared; +class ControllerTestVO { + final int input; + int? doubled; + int? squared; - ControllerTestVO( int this.input ){} + ControllerTestVO(this.input) {} } -class ControllerTestMacroCommand extends mvc.MacroCommand -{ - void initializeMacroCommand() - { +class ControllerTestMacroCommand extends mvc.MacroCommand { + void initializeMacroCommand() { // add the subcommands - addSubCommand( () => new ControllerTestDoubleInputCommand() ); - addSubCommand( () => new ControllerTestSquareInputCommand() ); + addSubCommand(() => new ControllerTestDoubleInputCommand()); + addSubCommand(() => new ControllerTestSquareInputCommand()); } } -class ControllerTestDoubleInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class ControllerTestDoubleInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note body ControllerTestVO vo = note.getBody(); @@ -135,14 +125,12 @@ class ControllerTestDoubleInputCommand extends mvc.SimpleCommand } } -class ControllerTestSquareInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class ControllerTestSquareInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note body ControllerTestVO vo = note.getBody(); // Compute the input squared vo.squared = vo.input * vo.input; } -} \ No newline at end of file +} diff --git a/test/Test_Facade.dart b/test/Test_Facade.dart index e09e264..1867606 100644 --- a/test/Test_Facade.dart +++ b/test/Test_Facade.dart @@ -1,378 +1,370 @@ part of puremvc_unit_tests; -class Test_Facade -{ - _tests() - { +class Test_Facade { + _tests() { // Test the Facade specific functionality - group('Facade::IFacade', () - { + group('Facade::IFacade', () { test('getInstance()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Make sure a Facade instance was returned - expect( facade, isNotNull ); + expect(facade, isNotNull); // Call getInstance() again - mvc.IFacade again = mvc.Facade.getInstance( multitonKey ); + final again = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Make sure the same Facade instance was returned - expect( facade, same(again) ); + expect(facade, same(again)); // Make sure the Facade's multitonKey was set - expect( facade.multitonKey, equals(multitonKey) ); + expect(facade.multitonKey, equals(multitonKey)); // Make sure the Model was created - expect( facade.model, isNotNull ); + expect(facade.model, isNotNull); // Make sure the Model's multitonKey was set - expect( facade.model.multitonKey, equals(multitonKey) ); + expect(facade.model!.multitonKey, equals(multitonKey)); // Make sure the View was created - expect( facade.view, isNotNull ); + expect(facade.view, isNotNull); // Make sure the View's multitonKey was set - expect( facade.view.multitonKey, equals(multitonKey) ); + expect(facade.view!.multitonKey, equals(multitonKey)); // Make sure the Controller was created - expect( facade.controller, isNotNull ); + expect(facade.controller, isNotNull); // Make sure the Controller's multitonKey was set - expect( facade.controller.multitonKey, equals(multitonKey) ); + expect(facade.controller!.multitonKey, equals(multitonKey)); }); test('getInstance(), hasCore()', () { - // Make sure it's not reported as registered first String multitonKey = "FacadeTest0"; - expect( mvc.Facade.hasCore( multitonKey ), isFalse ); + expect(mvc.Facade.hasCore(multitonKey), isFalse); // Get a unique multiton instance of Facade - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Make sure it's registered - expect( mvc.Facade.hasCore( multitonKey ), isTrue ); + expect(mvc.Facade.hasCore(multitonKey), isTrue); }); test('removeCore(), hasCore()', () { - // Get a unique multiton instance of Facade String multitonKey = "FacadeTest1"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Make sure it's registered - expect( mvc.Facade.hasCore( multitonKey ), isTrue ); + expect(mvc.Facade.hasCore(multitonKey), isTrue); // Remove the core mvc.Facade.removeCore(multitonKey); // Make sure the core is no longer registered - expect( mvc.Facade.hasCore( multitonKey ), isFalse ); + expect(mvc.Facade.hasCore(multitonKey), isFalse); }); }); // Test the Facade's IController interface functionality - group('Facade::IController', () - { + group('Facade::IController', () { test('registerCommand(), hasCommand()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest2"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Command String noteName = "FacadeTest2Note"; - facade.registerCommand( noteName, () => new FacadeTestMacroCommand() ); + facade.registerCommand(noteName, () => new FacadeTestMacroCommand()); // Make sure it's registered - expect( facade.hasCommand( noteName ), isTrue ); + expect(facade.hasCommand(noteName), isTrue); }); test('sendNotification() ->SimpleCommand', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest3"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Command String noteName = "FacadeTest3Note"; - facade.registerCommand( noteName, () => new FacadeTestDoubleInputCommand() ); + facade.registerCommand(noteName, () => new FacadeTestDoubleInputCommand()); // Create a value object - FacadeTestVO vo = new FacadeTestVO( 5 ); + FacadeTestVO vo = new FacadeTestVO(5); // Have the Facade send the note, triggering the Command - facade.sendNotification( noteName, vo ); + facade.sendNotification(noteName, vo); // Make sure the Command executed - expect( vo.doubled, equals(10) ); - expect( vo.squared, equals(null) ); + expect(vo.doubled, equals(10)); + expect(vo.squared, equals(null)); }); test('sendNotification() ->MacroCommand', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest4"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Command String noteName = "FacadeTest4Note"; - facade.registerCommand( noteName, () => new FacadeTestMacroCommand() ); + facade.registerCommand(noteName, () => new FacadeTestMacroCommand()); // Create a value object - FacadeTestVO vo = new FacadeTestVO( 5 ); + FacadeTestVO vo = new FacadeTestVO(5); // Have the Facade execute the Command - facade.sendNotification( noteName, vo ); + facade.sendNotification(noteName, vo); // Make sure the Command executed - expect( vo.doubled, equals(10) ); - expect( vo.squared, equals(25) ); + expect(vo.doubled, equals(10)); + expect(vo.squared, equals(25)); }); test('removeCommand()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest5"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Command String noteName = "FacadeTest5Note"; - facade.registerCommand( noteName, () => new FacadeTestMacroCommand() ); + facade.registerCommand(noteName, () => new FacadeTestMacroCommand()); // Make sure it's registered - expect( facade.hasCommand( noteName ), isTrue ); + expect(facade.hasCommand(noteName), isTrue); // Remove the Command - facade.removeCommand( noteName ); + facade.removeCommand(noteName); // Make sur the Controller doesn't know about it any more - expect( facade.hasCommand( noteName ), isFalse ); + expect(facade.hasCommand(noteName), isFalse); }); }); // Test the Facade's IView interface functionality - group('Facade::IView', () - { + group('Facade::IView', () { test('registerMediator(), hasMediator()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest6"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Mediator String mediatorName = "FacadeTest6Mediator"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); + facade.registerMediator(mediator); // Make sure it's registered - expect( facade.hasMediator( mediatorName ), isTrue ); + expect(facade.hasMediator(mediatorName), isTrue); }); test('retrieveMediator()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest7"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Mediator String mediatorName = "FacadeTest7Mediator"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); + facade.registerMediator(mediator); // Make sure same mediator is retrieved - expect( facade.retrieveMediator( mediatorName ), same(mediator) ); + expect(facade.retrieveMediator(mediatorName), same(mediator)); }); test('removeMediator()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest8"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Mediator String mediatorName = "FacadeTest8Mediator"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); + facade.registerMediator(mediator); // Make sure it's registered - expect( facade.hasMediator( mediatorName ), isTrue ); + expect(facade.hasMediator(mediatorName), isTrue); // Remove Mediator - facade.removeMediator( mediatorName ); + facade.removeMediator(mediatorName); // Make sure the Facade no longer knows about it - expect( facade.hasMediator( mediatorName ), isFalse ); + expect(facade.hasMediator(mediatorName), isFalse); }); test('registerObserver(), notifyObserver()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest8"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register an Observer using this test // instance's facadeTestMethod as the callback String noteName = "FacadeTest8Note"; - mvc.IObserver observer = new mvc.Observer( facadeTestMethod, this ); - facade.registerObserver( noteName, observer ); + mvc.IObserver observer = new mvc.Observer(facadeTestMethod, this); + facade.registerObserver(noteName, observer); // Create a notification - mvc.INotification note = new mvc.Notification( noteName ); + mvc.INotification note = new mvc.Notification(noteName); // Have the Facade notify the Observer - facade.notifyObservers( note ); + facade.notifyObservers(note); // Make sure the callback was executed - expect( facadeTestVar, equals(noteName) ); + expect(facadeTestVar, equals(noteName)); }); test('registerMediator(), ->mediator.onRegister()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest9"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component FacadeTestViewComponent vc = new FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator( vc ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new FacadeTestMediator(vc); + facade.registerMediator(mediator); // Make sure it's registered - expect( facade.hasMediator( FacadeTestMediator.NAME ), isTrue ); + expect(facade.hasMediator(FacadeTestMediator.NAME), isTrue); // Make sure the Mediator's onRegister() method was called - expect( vc.onRegisterCalled, isTrue ); + expect(vc.onRegisterCalled, isTrue); }); test('removeMediator(), ->mediator.onRemove()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest10"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component FacadeTestViewComponent vc = new FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator( vc ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new FacadeTestMediator(vc); + facade.registerMediator(mediator); // Make sure it's registered - expect( facade.hasMediator( FacadeTestMediator.NAME ), isTrue ); + expect(facade.hasMediator(FacadeTestMediator.NAME), isTrue); // Remove the Mediator - facade.removeMediator( FacadeTestMediator.NAME ); + facade.removeMediator(FacadeTestMediator.NAME); // Make sure the Mediator's onRemove() method was called - expect( vc.onRemoveCalled, isTrue ); + expect(vc.onRemoveCalled, isTrue); }); test('registerMediator(), ->mediator.listNotificationInterests()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest11"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component FacadeTestViewComponent vc = new FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator( vc ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new FacadeTestMediator(vc); + facade.registerMediator(mediator); // Make sure the Mediator's listNotificationInterests() method was called - expect( vc.listNotificationInterestsCalled, isTrue ); + expect(vc.listNotificationInterestsCalled, isTrue); }); test('sendNotification(), ->handleNotification()', () { // Get a unique multiton instance of Facade String multitonKey = "FacadeTest12"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component FacadeTestViewComponent vc = new FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator( vc ); - facade.registerMediator( mediator ); + mvc.IMediator mediator = new FacadeTestMediator(vc); + facade.registerMediator(mediator); // Send the Notification - facade.sendNotification( FacadeTestNotes.NOTE_2 ); + facade.sendNotification(FacadeTestNotes.NOTE_2); // Make sure the Mediator's listNotificationInterests() method was called - expect( vc.handleNotificationCalled, isTrue ); + expect(vc.handleNotificationCalled, isTrue); }); }); // Test the Facade's IModel interface functionality - group('Facade::IModel', () - { + group('Facade::IModel', () { test('registerProxy(), hasProxy()', () { // Unique multiton instance of Facade String multitonKey = "FacadeTest13"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy String proxyName = "FacadeTest13Proxy"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - facade.registerProxy( proxy ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + facade.registerProxy(proxy); // Make sure it's there - expect( facade.hasProxy( proxyName ), isTrue ); + expect(facade.hasProxy(proxyName), isTrue); }); test('retrieveProxy()', () { // Unique multiton instance of Facade String multitonKey = "FacadeTest14"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy String proxyName = "FacadeTest14Proxy"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - facade.registerProxy( proxy ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + facade.registerProxy(proxy); // Make sure same Proxy is retrieved - expect( facade.retrieveProxy( proxyName ), same(proxy) ); + expect(facade.retrieveProxy(proxyName), same(proxy)); }); test('removeProxy(), hasProxy()', () { // Unique multiton instance of Facade String multitonKey = "FacadeTest15"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy String proxyName = "FacadeTest15Proxy"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - facade.registerProxy( proxy ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + facade.registerProxy(proxy); // Make sure it is returned when removed - expect( facade.removeProxy( proxyName ), same(proxy) ); + expect(facade.removeProxy(proxyName), same(proxy)); // Make sure Facade doesn't know about it anymore - expect( facade.hasProxy( proxyName ), isFalse ); + expect(facade.hasProxy(proxyName), isFalse); }); test('registerProxy(), ->proxy.onRegister()', () { // Unique multiton instance of Facade String multitonKey = "FacadeTest16"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy mvc.IProxy proxy = new FacadeTestProxy(); - facade.registerProxy( proxy ); + facade.registerProxy(proxy); // Make sure the Proxy's onRegister() method is called - expect( proxy.getData(), equals(FacadeTestProxy.ON_REGISTER_CALLED) ); + expect(proxy.getData(), equals(FacadeTestProxy.ON_REGISTER_CALLED)); }); test('removeProxy(), ->proxy.onRemove()', () { // Unique multiton instance of Facade String multitonKey = "FacadeTest17"; - mvc.IFacade facade = mvc.Facade.getInstance( multitonKey ); + final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy mvc.IProxy proxy = new FacadeTestProxy(); - facade.registerProxy( proxy ); + facade.registerProxy(proxy); // Remove the Proxy - facade.removeProxy( FacadeTestProxy.NAME ); + facade.removeProxy(FacadeTestProxy.NAME); // Make sure the Proxy's onRemove() method is called - expect( proxy.getData(), equals(FacadeTestProxy.ON_REMOVE_CALLED) ); + expect(proxy.getData(), equals(FacadeTestProxy.ON_REMOVE_CALLED)); }); }); } @@ -383,112 +375,100 @@ class Test_Facade } // A callback method for the test Observer -void facadeTestMethod( mvc.INotification note ) { +void facadeTestMethod(mvc.INotification note) { facadeTestVar = note.getName(); } -String facadeTestVar; +String? facadeTestVar; class FacadeTestNotes { - static String NOTE_1 = "FacadeTest/note/name/1"; static String NOTE_2 = "FacadeTest/note/name/2"; static String NOTE_3 = "FacadeTest/note/name/3"; } -class FacadeTestViewComponent -{ +class FacadeTestViewComponent { bool onRegisterCalled = false; bool onRemoveCalled = false; bool listNotificationInterestsCalled = false; bool handleNotificationCalled = false; } -class FacadeTestMediator extends mvc.Mediator -{ +class FacadeTestMediator extends mvc.Mediator { // Name Mediator will be registered as static String NAME = "FacadeTestMediator"; // Constructor - FacadeTestMediator( FacadeTestViewComponent viewComponent ):super( NAME, viewComponent ){} + FacadeTestMediator(FacadeTestViewComponent viewComponent) : super(NAME, viewComponent) {} // Accessors that cast viewComponent to the correct type for this Mediator - FacadeTestViewComponent get vc { return viewComponent; } - void set vc( FacadeTestViewComponent facadeTestViewComponent ) { viewComponent = facadeTestViewComponent; } + FacadeTestViewComponent get vc { + return viewComponent; + } + + void set vc(FacadeTestViewComponent facadeTestViewComponent) { + viewComponent = facadeTestViewComponent; + } // Called when Mediator is registered - void onRegister() - { + void onRegister() { vc.onRegisterCalled = true; } // Also called when Mediator is registered - List listNotificationInterests() - { + List listNotificationInterests() { vc.listNotificationInterestsCalled = true; - return [ FacadeTestNotes.NOTE_1, - FacadeTestNotes.NOTE_2, - FacadeTestNotes.NOTE_3 ]; + return [FacadeTestNotes.NOTE_1, FacadeTestNotes.NOTE_2, FacadeTestNotes.NOTE_3]; } // Called when a notification this Mediator is interested in is sent - void handleNotification( mvc.INotification note ) - { + void handleNotification(mvc.INotification note) { vc.handleNotificationCalled = true; } // Called when Mediator is removed - void onRemove() - { + void onRemove() { vc.onRemoveCalled = true; } } -class FacadeTestProxy extends mvc.Proxy -{ +class FacadeTestProxy extends mvc.Proxy { static String NAME = "FacadeTestProxyClass"; static String FRESH = "Fresh Instance"; static String ON_REGISTER_CALLED = "onRegister() Called"; static String ON_REMOVE_CALLED = "onRemove() Called"; - FacadeTestProxy():super( NAME ){ - setData( FRESH ); + FacadeTestProxy() : super(NAME) { + setData(FRESH); } - void onRegister() - { - setData( ON_REGISTER_CALLED ); + void onRegister() { + setData(ON_REGISTER_CALLED); } - void onRemove() - { - setData( ON_REMOVE_CALLED ); + void onRemove() { + setData(ON_REMOVE_CALLED); } } -class FacadeTestVO -{ - int input; - int doubled; - int squared; +class FacadeTestVO { + final int input; + int? doubled; + int? squared; - FacadeTestVO( int this.input ){} + FacadeTestVO(this.input) {} } -class FacadeTestMacroCommand extends mvc.MacroCommand -{ - void initializeMacroCommand() - { +class FacadeTestMacroCommand extends mvc.MacroCommand { + void initializeMacroCommand() { // add the subcommands - addSubCommand( () => new FacadeTestDoubleInputCommand() ); - addSubCommand( () => new FacadeTestSquareInputCommand() ); + addSubCommand(() => new FacadeTestDoubleInputCommand()); + addSubCommand(() => new FacadeTestSquareInputCommand()); } } -class FacadeTestDoubleInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class FacadeTestDoubleInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note body FacadeTestVO vo = note.getBody(); @@ -497,10 +477,8 @@ class FacadeTestDoubleInputCommand extends mvc.SimpleCommand } } -class FacadeTestSquareInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class FacadeTestSquareInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note body FacadeTestVO vo = note.getBody(); diff --git a/test/Test_MacroCommand.dart b/test/Test_MacroCommand.dart index 776c477..5272411 100644 --- a/test/Test_MacroCommand.dart +++ b/test/Test_MacroCommand.dart @@ -1,15 +1,12 @@ part of puremvc_unit_tests; -class Test_MacroCommand -{ - _tests() - { - group('MacroCommand', () - { +class Test_MacroCommand { + _tests() { + group('MacroCommand', () { test('Constructor', () { // Create a MacroCommand mvc.ICommand macroCommand = new MacroCommandTestCommand(); - expect( macroCommand, isNotNull ); + expect(macroCommand, isNotNull); }); test('execute()', () { @@ -17,13 +14,13 @@ class Test_MacroCommand mvc.ICommand macroCommand = new MacroCommandTestCommand(); // Create a VO and a Notification to pass it to the Command with - MacroCommandTestVO vo = new MacroCommandTestVO( 5 ); - mvc.INotification note = new mvc.Notification( "MacroCommandTest", vo ); + MacroCommandTestVO vo = new MacroCommandTestVO(5); + mvc.INotification note = new mvc.Notification("MacroCommandTest", vo); // Execute the MacroCommand execute the note macroCommand.execute(note); - expect( vo.doubled, equals(10) ); - expect( vo.squared, equals(25) ); + expect(vo.doubled, equals(10)); + expect(vo.squared, equals(25)); }); test('initializeNotifier()', () { @@ -32,10 +29,10 @@ class Test_MacroCommand // Call initializeNotifier() String multitonKey = "MacroCommandTest"; - notifier.initializeNotifier( multitonKey ); + notifier.initializeNotifier(multitonKey); // Make sure MacroCommand's multitonKey was set - expect( notifier.multitonKey, isNotNull ); + expect(notifier.multitonKey, isNotNull); }); }); } @@ -45,28 +42,24 @@ class Test_MacroCommand } } -class MacroCommandTestVO -{ - int input; - int doubled; - int squared; +class MacroCommandTestVO { + final int input; + int? doubled; + int? squared; - MacroCommandTestVO( int this.input ) {} + MacroCommandTestVO(this.input) {} } -class MacroCommandTestCommand extends mvc.MacroCommand -{ +class MacroCommandTestCommand extends mvc.MacroCommand { void initializeMacroCommand() { // Add the subcommands - addSubCommand( () => new MacroCommandTestDoubleInputCommand() ); - addSubCommand( () => new MacroCommandTestSquareInputCommand() ); + addSubCommand(() => new MacroCommandTestDoubleInputCommand()); + addSubCommand(() => new MacroCommandTestSquareInputCommand()); } } -class MacroCommandTestDoubleInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class MacroCommandTestDoubleInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note body MacroCommandTestVO vo = note.getBody(); @@ -75,14 +68,12 @@ class MacroCommandTestDoubleInputCommand extends mvc.SimpleCommand } } -class MacroCommandTestSquareInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class MacroCommandTestSquareInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note body MacroCommandTestVO vo = note.getBody(); // Compute the input doubled vo.squared = vo.input * vo.input; } -} \ No newline at end of file +} diff --git a/test/Test_Mediator.dart b/test/Test_Mediator.dart index b09424b..d1d7e5f 100644 --- a/test/Test_Mediator.dart +++ b/test/Test_Mediator.dart @@ -1,28 +1,25 @@ part of puremvc_unit_tests; -class Test_Mediator -{ - _tests() - { - group('Mediator', () - { +class Test_Mediator { + _tests() { + group('Mediator', () { test('Constructor', () { // Create a Mediator String mediatorName = "TestMediator1"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); // Make sure it was created - expect( mediator, isNotNull ); + expect(mediator, isNotNull); }); test('getMediatorName()', () { // Create a Mediator String mediatorName = "TestMediator2"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); // Make sure the Mediator's name was set - expect( mediator.getName(), equals(mediatorName) ); - expect( mediator.name, equals(mediatorName) ); + expect(mediator.getName(), equals(mediatorName)); + expect(mediator.name, equals(mediatorName)); }); test('Constructor +viewComponent, getViewComponent(), .viewComponent', () { @@ -31,11 +28,11 @@ class Test_Mediator // Create a Mediator with the view component String mediatorName = "TestMediator3"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName, viewComponent ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName, viewComponent); // Make sure the view component was set - expect( mediator.getViewComponent(), same(viewComponent) ); - expect( mediator.viewComponent, same(viewComponent) ); + expect(mediator.getViewComponent(), same(viewComponent)); + expect(mediator.viewComponent, same(viewComponent)); }); test('setViewComponent(), getViewComponent()', () { @@ -44,27 +41,27 @@ class Test_Mediator // Create a Mediator String mediatorName = "TestMediator4"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); // Call setViewComponent() - mediator.setViewComponent( viewComponent ); + mediator.setViewComponent(viewComponent); // Make sure the view component was set - expect( mediator.getViewComponent(), same(viewComponent) ); - expect( mediator.viewComponent, same(viewComponent) ); + expect(mediator.getViewComponent(), same(viewComponent)); + expect(mediator.viewComponent, same(viewComponent)); }); test('initializeNotifier()', () { // Create a Mediator String mediatorName = "TestMediator5"; - mvc.INotifier notifier = new mvc.Mediator( mediatorName ); + mvc.INotifier notifier = new mvc.Mediator(mediatorName); // Call initializeNotifier() String multitonKey = "MediatorTestKey"; - notifier.initializeNotifier( multitonKey ); + notifier.initializeNotifier(multitonKey); // Make sure the Mediator's multitonKey was set - expect( notifier.multitonKey, isNotNull ); + expect(notifier.multitonKey, isNotNull); }); }); } diff --git a/test/Test_Model.dart b/test/Test_Model.dart index 4df29ba..80dbbc8 100644 --- a/test/Test_Model.dart +++ b/test/Test_Model.dart @@ -1,94 +1,91 @@ part of puremvc_unit_tests; -class Test_Model -{ - _tests() - { - group('Model', () - { +class Test_Model { + _tests() { + group('Model', () { test('getInstance()', () { // Unique multiton instance of Model String multitonKey = "ModelTest1"; - mvc.IModel model = mvc.Model.getInstance( multitonKey ); - expect( model, isNotNull ); + final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; + expect(model, isNotNull); // Same instance retrieved again - mvc.IModel again = mvc.Model.getInstance( multitonKey ); - expect( model, same(again) ); + final again = mvc.Model.getInstance(multitonKey) as mvc.IModel; + expect(model, same(again)); }); test('registerProxy(), hasProxy()', () { // Unique multiton instance of Model String multitonKey = "ModelTest2"; - mvc.IModel model = mvc.Model.getInstance( multitonKey ); + final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy String proxyName = "ModelTest2Proxy"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - model.registerProxy( proxy ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + model.registerProxy(proxy); // Make sure it's there - expect( model.hasProxy( proxyName ), isTrue ); + expect(model.hasProxy(proxyName), isTrue); }); test('retrieveProxy()', () { // Unique multiton instance of Model String multitonKey = "ModelTest3"; - mvc.IModel model = mvc.Model.getInstance( multitonKey ); + final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy String proxyName = "ModelTest3Proxy"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - model.registerProxy( proxy ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + model.registerProxy(proxy); // Make sure same Proxy is retrieved - expect( model.retrieveProxy( proxyName ), same(proxy) ); + expect(model.retrieveProxy(proxyName), same(proxy)); }); test('removeProxy(), hasProxy()', () { // Unique multiton instance of Model String multitonKey = "ModelTest4"; - mvc.IModel model = mvc.Model.getInstance( multitonKey ); + final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy String proxyName = "ModelTest4Proxy"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - model.registerProxy( proxy ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + model.registerProxy(proxy); // Make sure it is returned when removed - expect( model.removeProxy( proxyName ), same(proxy) ); + expect(model.removeProxy(proxyName), same(proxy)); // Make sure Model doesn't know about it anymore - expect( model.hasProxy( proxyName ), isFalse ); + expect(model.hasProxy(proxyName), isFalse); }); test('Model calls onRegister()', () { // Unique multiton instance of Model String multitonKey = "ModelTest5"; - mvc.IModel model = mvc.Model.getInstance( multitonKey ); + final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy mvc.IProxy proxy = new ModelTestProxy(); - model.registerProxy( proxy ); + model.registerProxy(proxy); // Make sure the Model calls the Proxy's onRegister() method - expect( proxy.getData(), equals(ModelTestProxy.ON_REGISTER_CALLED) ); + expect(proxy.getData(), equals(ModelTestProxy.ON_REGISTER_CALLED)); }); test('Model calls onRemove()', () { // Unique multiton instance of Model String multitonKey = "ModelTest6"; - mvc.IModel model = mvc.Model.getInstance( multitonKey ); + final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy mvc.IProxy proxy = new ModelTestProxy(); - model.registerProxy( proxy ); + model.registerProxy(proxy); // Remove the Proxy - model.removeProxy( ModelTestProxy.NAME ); + model.removeProxy(ModelTestProxy.NAME); // Make sure the Model calls the Proxy's onRemove() method - expect( proxy.getData(), equals(ModelTestProxy.ON_REMOVE_CALLED) ); + expect(proxy.getData(), equals(ModelTestProxy.ON_REMOVE_CALLED)); }); }); } @@ -98,24 +95,21 @@ class Test_Model } } -class ModelTestProxy extends mvc.Proxy -{ +class ModelTestProxy extends mvc.Proxy { static String NAME = "ModelTestProxyClass"; static String FRESH = "Fresh Instance"; static String ON_REGISTER_CALLED = "onRegister() Called"; static String ON_REMOVE_CALLED = "onRemove() Called"; - ModelTestProxy():super( NAME ){ - setData( FRESH ); + ModelTestProxy() : super(NAME) { + setData(FRESH); } - void onRegister() - { - setData( ON_REGISTER_CALLED ); + void onRegister() { + setData(ON_REGISTER_CALLED); } - void onRemove() - { - setData( ON_REMOVE_CALLED ); + void onRemove() { + setData(ON_REMOVE_CALLED); } } diff --git a/test/Test_Notification.dart b/test/Test_Notification.dart index db039b2..b0bf266 100644 --- a/test/Test_Notification.dart +++ b/test/Test_Notification.dart @@ -1,50 +1,44 @@ part of puremvc_unit_tests; -class Test_Notification -{ - _tests() - { - group('Notification', () - { +class Test_Notification { + _tests() { + group('Notification', () { test('Constructor minimum args', () { // Create a Notification with a name only - String name = "Test"; - mvc.INotification note = new mvc.Notification( name ); + String name = "Test"; + mvc.INotification note = new mvc.Notification(name); // Make sure the note was created - expect( note, isNotNull ); + expect(note, isNotNull); }); test('.name, getName()', () { // Create a Notification with name only - String name = "Test"; - mvc.INotification note = new mvc.Notification( name ); + String name = "Test"; + mvc.INotification note = new mvc.Notification(name); // Make sure the name was set - expect( name, equals( note.getName() ) ); - expect( name, equals( note.name ) ); + expect(name, equals(note.getName())); }); test('.type, getType()', () { // Create a Notification with name and type only - String name = "Test"; - String type = "Type"; - mvc.INotification note = new mvc.Notification( name, null, type ); + String name = "Test"; + String type = "Type"; + mvc.INotification note = new mvc.Notification(name, null, type); // Make Sure the type was set - expect( type, equals( note.getType() ) ); - expect( type, equals( note.type ) ); + expect(type, equals(note.getType())); }); test('.body, getBody()', () { // Create a Notification with a body - String name = "Test"; - List body = new List(); - mvc.INotification note = new mvc.Notification( name, body ); + String name = "Test"; + List body = List.empty(growable: true); + mvc.INotification note = new mvc.Notification(name, body); // Make sure the body was set - expect( body, equals( note.getBody() ) ); - expect( body, equals( note.body ) ); + expect(body, equals(note.getBody())); }); }); } @@ -52,4 +46,4 @@ class Test_Notification run() { _tests(); } -} \ No newline at end of file +} diff --git a/test/Test_Observer.dart b/test/Test_Observer.dart index cab28bf..a2a0581 100644 --- a/test/Test_Observer.dart +++ b/test/Test_Observer.dart @@ -1,103 +1,93 @@ part of puremvc_unit_tests; -class Test_Observer -{ - _tests() - { - group('Observer', () - { +class Test_Observer { + _tests() { + group('Observer', () { test('Constructor null args', () { // Create a blind Observer - mvc.IObserver observer = new mvc.Observer( null, null ); + mvc.IObserver observer = new mvc.Observer(() {}, null); // Make sure Observer was created - expect( observer, isNotNull ); + expect(observer, isNotNull); }); test('Constructor complete args', () { // Create an observer with callback method and caller instance defined - mvc.IObserver observer = new mvc.Observer( this.observerTestMethod, this ); + mvc.IObserver observer = new mvc.Observer(this.observerTestMethod, this); // Make sure the Observer was created - expect( observer, isNotNull ); + expect(observer, isNotNull); // Make sure caller and callback were set - expect( observer.getNotifyMethod(), isNotNull ); - expect( observer.notifyMethod, isNotNull ); - expect( observer.getNotifyContext(), isNotNull ); - expect( observer.notifyContext, isNotNull ); - + expect(observer.getNotifyMethod(), isNotNull); + expect(observer.getNotifyContext(), isNotNull); }); test('Constructor minimum args', () { - // Create an Observer with callack only - mvc.IObserver observer = new mvc.Observer( this.observerTestMethod ); + // Create an Observer with callback only + mvc.IObserver observer = new mvc.Observer(this.observerTestMethod); // Make sure Observer was created - expect( observer, isNotNull ); + expect(observer, isNotNull); // Make sure callback method was set - expect( observer.getNotifyMethod(), isNotNull ); + expect(observer.getNotifyMethod(), isNotNull); }); test('setNotifyMethod()', () { // Create an Observer - mvc.IObserver observer = new mvc.Observer( null ); + mvc.IObserver observer = new mvc.Observer(null); // Call setNotifyMethod() - observer.setNotifyMethod( observerTestMethod ); + observer.setNotifyMethod(observerTestMethod); // Make sure callback method was set - expect( observer.getNotifyMethod(), isNotNull ); - expect( observer.notifyMethod, isNotNull ); - + expect(observer.getNotifyMethod(), isNotNull); }); test('setNotifyContext()', () { // Create an Observer - mvc.IObserver observer = new mvc.Observer( null ); + mvc.IObserver observer = new mvc.Observer(null); // Call setNotifyContext() - observer.setNotifyContext( this ); + observer.setNotifyContext(this); // Make sure caller was set - expect( observer.getNotifyContext(), isNotNull ); - expect( observer.getNotifyContext(), same(this) ); - expect( observer.notifyContext, isNotNull ); - expect( observer.notifyContext, same(this) ); + expect(observer.getNotifyContext(), isNotNull); + expect(observer.getNotifyContext(), same(this)); }); test('compareNotifyContext()', () { // Create an Observer with only a caller - mvc.IObserver observer = new mvc.Observer( null, this ); + mvc.IObserver observer = new mvc.Observer(null, this); // Make sure the caller was set - expect( observer.compareNotifyContext( this ), isTrue ); + expect(observer.compareNotifyContext(this), isTrue); }); test('notifyObserver()', () { // Create an Observer with this test instance's observerTestMethod() as the callback - mvc.IObserver observer = new mvc.Observer( this.observerTestMethod, this ); + mvc.IObserver observer = new mvc.Observer(this.observerTestMethod, this); // Create a Notification String name = "Test"; - mvc.INotification note = new mvc.Notification( name ); + mvc.INotification note = new mvc.Notification(name); // Notify the Observer - observer.notifyObserver( note ); + observer.notifyObserver(note); // Make sure the Observer was notified - expect( observerTestNote, isNotNull ); - expect( observerTestNote.name, equals(name) ); + expect(observerTestNote, isNotNull); + expect(observerTestNote!.getName(), equals(name)); }); }); } // Test Notification - mvc.INotification observerTestNote; + mvc.INotification? observerTestNote; // Callback method for Observer - observerTestMethod( mvc.INotification note ){ + observerTestMethod(mvc.INotification note) { observerTestNote = note; } diff --git a/test/Test_Proxy.dart b/test/Test_Proxy.dart index af8accf..fc857d0 100644 --- a/test/Test_Proxy.dart +++ b/test/Test_Proxy.dart @@ -1,25 +1,22 @@ part of puremvc_unit_tests; -class Test_Proxy -{ - _tests() - { - group('ProxyTest', () - { +class Test_Proxy { + _tests() { + group('ProxyTest', () { test('Constructor +name', () { String proxyName = "TestProxy1"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); - expect( proxy, isNotNull ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); + expect(proxy, isNotNull); }); test('getName(), .name', () { // Create a Proxy String proxyName = "TestProxy2"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); // Make sure the Proxy name was set - expect( proxy.getName(), equals(proxyName) ); - expect( proxy.name, equals(proxyName) ); + expect(proxy.getName(), equals(proxyName)); + expect(proxy.name, equals(proxyName)); }); test('Constructor +data, getData(), .data', () { @@ -28,14 +25,14 @@ class Test_Proxy // Create a Proxy with that data String proxyName = "TestProxy3"; - mvc.IProxy proxy = new mvc.Proxy( proxyName, data ); + mvc.IProxy proxy = new mvc.Proxy(proxyName, data); // Make sure the Proxy was created - expect( proxy, isNotNull ); + expect(proxy, isNotNull); // Make sure the data was set - expect( proxy.getData(), same(data) ); - expect( proxy.data, same(data) ); + expect(proxy.getData(), same(data)); + expect(proxy.data, same(data)); }); test('setData(), getData(), .data', () { @@ -44,28 +41,27 @@ class Test_Proxy // Create a Proxy String proxyName = "TestProxy4"; - mvc.IProxy proxy = new mvc.Proxy( proxyName ); + mvc.IProxy proxy = new mvc.Proxy(proxyName); // Call setData() - proxy.setData( data ); + proxy.setData(data); // Make sure the data was set - expect( proxy.getData(), same(data) ); - expect( proxy.data, same(data) ); - + expect(proxy.getData(), same(data)); + expect(proxy.data, same(data)); }); test('initializeNotifier()', () { // Create a Proxy String proxyName = "TestProxy5"; - mvc.INotifier notifier = new mvc.Proxy( proxyName ); + mvc.INotifier notifier = new mvc.Proxy(proxyName); // Call initializeNotifier() String multitonKey = "ProxyTestKey"; - notifier.initializeNotifier( multitonKey ); + notifier.initializeNotifier(multitonKey); // Make sure the Proxy's multitonKey was set - expect( notifier.multitonKey, isNotNull ); + expect(notifier.multitonKey, isNotNull); }); }); } diff --git a/test/Test_SimpleCommand.dart b/test/Test_SimpleCommand.dart index dfd16ca..9744cf0 100644 --- a/test/Test_SimpleCommand.dart +++ b/test/Test_SimpleCommand.dart @@ -1,30 +1,27 @@ part of puremvc_unit_tests; -class Test_SimpleCommand -{ - _tests() - { - group('SimpleCommand', () - { +class Test_SimpleCommand { + _tests() { + group('SimpleCommand', () { test('Constructor', () { - // Create a SimpeCommand + // Create a SimpleCommand mvc.ICommand simpleCommand = new SimpleCommandTestDoubleInputCommand(); - expect( simpleCommand, isNotNull ); + expect(simpleCommand, isNotNull); }); test('execute()', () { - // Create a SimpeCommand + // Create a SimpleCommand mvc.ICommand simpleCommand = new SimpleCommandTestDoubleInputCommand(); // Crete a VO and a Notification to pass it to the Command with - SimpleCommandTestVO vo = new SimpleCommandTestVO( 5 ); - mvc.INotification note = new mvc.Notification( "SimpleCommandTestNote", vo ); + SimpleCommandTestVO vo = new SimpleCommandTestVO(5); + mvc.INotification note = new mvc.Notification("SimpleCommandTestNote", vo); // Execute the SimpleCommand with the note - simpleCommand.execute( note ); + simpleCommand.execute(note); // Make sure the SimpleCommand logic was executed - expect( vo.result, equals(10) ); + expect(vo.result, equals(10)); }); test('initializeNotifier()', () { @@ -33,10 +30,10 @@ class Test_SimpleCommand // call initializeNotifier() String multitonKey = "SimpleCommandTest"; - notifier.initializeNotifier( multitonKey ); + notifier.initializeNotifier(multitonKey); // Make sure the SimpleCommand's multitonKey was set - expect( notifier.multitonKey, isNotNull ); + expect(notifier.multitonKey, isNotNull); }); }); } @@ -46,23 +43,19 @@ class Test_SimpleCommand } } -class SimpleCommandTestVO -{ - SimpleCommandTestVO( int this.input ) { - } +class SimpleCommandTestVO { + SimpleCommandTestVO(this.input) {} - int input; - int result; + final int input; + int? result; } -class SimpleCommandTestDoubleInputCommand extends mvc.SimpleCommand -{ - void execute( mvc.INotification note ) - { +class SimpleCommandTestDoubleInputCommand extends mvc.SimpleCommand { + void execute(mvc.INotification note) { // Get the VO from the note SimpleCommandTestVO vo = note.getBody(); // Fabricate a result vo.result = 2 * vo.input; } -} \ No newline at end of file +} diff --git a/test/Test_View.dart b/test/Test_View.dart index 3ecfcda..aef71b9 100644 --- a/test/Test_View.dart +++ b/test/Test_View.dart @@ -1,182 +1,179 @@ part of puremvc_unit_tests; -class Test_View -{ - _tests() - { - group('ViewTest', () - { +class Test_View { + _tests() { + group('ViewTest', () { test('getInstance()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest1"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Make sure a View instance was returned - expect( view, isNotNull ); + expect(view, isNotNull); // Call getInstance() again - mvc.IView again = mvc.View.getInstance( multitonKey ); + final again = mvc.View.getInstance(multitonKey) as mvc.IView; // Make sure the same View instance was returned - expect( view, same(again) ); + expect(view, same(again)); }); test('registerMediator(), hasMediator()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest2"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Register a Mediator String mediatorName = "ViewTest3Mediator"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); + view.registerMediator(mediator); // Make sure it's registered - expect( view.hasMediator( mediatorName ), isTrue ); + expect(view.hasMediator(mediatorName), isTrue); }); test('retrieveMediator()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest3"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Register a Mediator String mediatorName = "ViewTest3Mediator"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); + view.registerMediator(mediator); // Make sure same mediator is retrieved - expect( view.retrieveMediator( mediatorName ), same(mediator) ); + expect(view.retrieveMediator(mediatorName), same(mediator)); }); test('removeMediator()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest4"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Register a Mediator String mediatorName = "ViewTest4Mediator"; - mvc.IMediator mediator = new mvc.Mediator( mediatorName ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new mvc.Mediator(mediatorName); + view.registerMediator(mediator); // Make sure it's registered - expect( view.hasMediator( mediatorName ), isTrue ); + expect(view.hasMediator(mediatorName), isTrue); // Remove Mediator - view.removeMediator( mediatorName ); + view.removeMediator(mediatorName); // Make sure the View no longer knows about it - expect( view.hasMediator( mediatorName ), isFalse ); + expect(view.hasMediator(mediatorName), isFalse); }); test('registerObserver(), notifyObserver()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest5"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Register an Observer using this test // instance's viewTestMethod as the callback String noteName = "ViewTest5Note"; - mvc.IObserver observer = new mvc.Observer( viewTestMethod, this ); - view.registerObserver( noteName, observer ); + mvc.IObserver observer = new mvc.Observer(viewTestMethod, this); + view.registerObserver(noteName, observer); // Create a notification - mvc.INotification note = new mvc.Notification( noteName ); + mvc.INotification note = new mvc.Notification(noteName); // Have the View notify the Observer - view.notifyObservers( note ); + view.notifyObservers(note); // Make sure the callback was executed - expect( viewTestVar, equals(noteName) ); + expect(viewTestVar, equals(noteName)); }); test('View calls onRegister()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest6"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component ViewTestViewComponent vc = new ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator( vc ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new ViewTestMediator(vc); + view.registerMediator(mediator); // Make sure it's registered - expect( view.hasMediator( ViewTestMediator.NAME ), isTrue ); + expect(view.hasMediator(ViewTestMediator.NAME), isTrue); // Make sure the Mediator's onRegister() method was called - expect( vc.onRegisterCalled, isTrue ); + expect(vc.onRegisterCalled, isTrue); }); test('View calls onRemove()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest7"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component ViewTestViewComponent vc = new ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator( vc ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new ViewTestMediator(vc); + view.registerMediator(mediator); // Make sure it's registered - expect( view.hasMediator( ViewTestMediator.NAME ), isTrue ); + expect(view.hasMediator(ViewTestMediator.NAME), isTrue); // Remove the Mediator - view.removeMediator( ViewTestMediator.NAME ); + view.removeMediator(ViewTestMediator.NAME); // Make sure the Mediator's onRemove() method was called - expect( vc.onRemoveCalled, isTrue ); + expect(vc.onRemoveCalled, isTrue); }); test('View calls listNotificationInterests()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest8"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component ViewTestViewComponent vc = new ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator( vc ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new ViewTestMediator(vc); + view.registerMediator(mediator); // Make sure the Mediator's listNotificationInterests() method was called - expect( vc.listNotificationInterestsCalled, isTrue ); + expect(vc.listNotificationInterestsCalled, isTrue); }); test('View calls handleNotification()', () { // Get a unique multiton instance of View String multitonKey = "ViewTest9"; - mvc.IView view = mvc.View.getInstance( multitonKey ); + final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component ViewTestViewComponent vc = new ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator( vc ); - view.registerMediator( mediator ); + mvc.IMediator mediator = new ViewTestMediator(vc); + view.registerMediator(mediator); // Create a Notification - mvc.INotification note = new mvc.Notification( ViewTestNotes.NOTE_2 ); + mvc.INotification note = new mvc.Notification(ViewTestNotes.NOTE_2); // Send the Notification - view.notifyObservers( note ); + view.notifyObservers(note); // Make sure the Mediator's listNotificationInterests() method was called - expect( vc.handleNotificationCalled, isTrue ); + expect(vc.handleNotificationCalled, isTrue); }); }); } // A callback method for the test Observer - void viewTestMethod( mvc.INotification note ) { + void viewTestMethod(mvc.INotification note) { viewTestVar = note.getName(); } - String viewTestVar; + String? viewTestVar; run() { _tests(); @@ -184,56 +181,52 @@ class Test_View } class ViewTestNotes { - static String NOTE_1 = "ViewTest/note/name/1"; static String NOTE_2 = "ViewTest/note/name/2"; static String NOTE_3 = "ViewTest/note/name/3"; } -class ViewTestViewComponent -{ +class ViewTestViewComponent { bool onRegisterCalled = false; bool onRemoveCalled = false; bool listNotificationInterestsCalled = false; bool handleNotificationCalled = false; } -class ViewTestMediator extends mvc.Mediator -{ +class ViewTestMediator extends mvc.Mediator { // Name Mediator will be registered as static String NAME = "ViewTestMediator"; // Constructor - ViewTestMediator( ViewTestViewComponent viewComponent ):super( NAME, viewComponent ){} + ViewTestMediator(ViewTestViewComponent viewComponent) : super(NAME, viewComponent) {} // Accessors that cast viewComponent to the correct type for this Mediator - ViewTestViewComponent get vc { return viewComponent; } - void set vc( ViewTestViewComponent viewTestViewComponent ) { viewComponent = viewTestViewComponent; } + ViewTestViewComponent get vc { + return viewComponent; + } + + void set vc(ViewTestViewComponent viewTestViewComponent) { + viewComponent = viewTestViewComponent; + } // Called when Mediator is registered - void onRegister() - { + void onRegister() { vc.onRegisterCalled = true; } // Also called when Mediator is registered - List listNotificationInterests() - { + List listNotificationInterests() { vc.listNotificationInterestsCalled = true; - return [ ViewTestNotes.NOTE_1, - ViewTestNotes.NOTE_2, - ViewTestNotes.NOTE_3 ]; + return [ViewTestNotes.NOTE_1, ViewTestNotes.NOTE_2, ViewTestNotes.NOTE_3]; } // Called when a notification this Mediator is interested in is sent - void handleNotification( mvc.INotification note ) - { + void handleNotification(mvc.INotification note) { vc.handleNotificationCalled = true; } // Called when Mediator is removed - void onRemove() - { + void onRemove() { vc.onRemoveCalled = true; } } diff --git a/test/Unit_Tests.dart b/test/Unit_Tests.dart index 30e7db8..fa27902 100644 --- a/test/Unit_Tests.dart +++ b/test/Unit_Tests.dart @@ -2,46 +2,37 @@ library puremvc_unit_tests; // DART HTML Library -import 'dart:html'; - -// The Unit Testing Framework for Dart -import 'package:unittest/unittest.dart'; -import 'package:unittest/html_enhanced_config.dart'; +// import 'dart:html'; // PureMVC Framework for Dart import 'package:puremvc/puremvc.dart' as mvc; +// The Unit Testing Framework for Dart +import 'package:test/test.dart'; +part 'Test_Controller.dart'; +part 'Test_Facade.dart'; +part 'Test_MacroCommand.dart'; +part 'Test_Mediator.dart'; +part 'Test_Model.dart'; // PureMVC Unit Tests part 'Test_Notification.dart'; part 'Test_Observer.dart'; -part 'Test_SimpleCommand.dart'; -part 'Test_MacroCommand.dart'; part 'Test_Proxy.dart'; -part 'Test_Mediator.dart'; -part 'Test_Model.dart'; +part 'Test_SimpleCommand.dart'; part 'Test_View.dart'; -part 'Test_Controller.dart'; -part 'Test_Facade.dart'; -class Unit_Tests -{ - Unit_Tests() - { - // unittestConfiguration = new Unit_Tests_Config(); - useHtmlEnhancedConfiguration(); - } - - void onTestResult( TestCase testCase ) { - write( "${testCase.result} ${testCase.currentGroup}" ); +class Unit_Tests { + Unit_Tests() {} - } - - void write(String message) { - document.querySelector('#status').innerHtml = message; - } + // void onTestResult(TestCase testCase) { + // write("${testCase.result} ${testCase.currentGroup}"); + // } + // + // void write(String message) { + // document.querySelector('#status')?.innerHtml = message; + // } void run() { - // Now, run the PureMVC Tests new Test_Notification().run(); new Test_Observer().run(); @@ -56,12 +47,10 @@ class Unit_Tests } } - /** * Application entry point. */ -void main() -{ +void main() { // Unit test program, reporting for duty! new Unit_Tests().run(); -} \ No newline at end of file +} From 41f0d38d3071db0806921fcb738d19808d7100aa Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sat, 5 Aug 2023 12:49:12 +0300 Subject: [PATCH 03/21] Use native method containsKey to check existence of the value for commandMap in Controller. --- lib/src/core/Controller.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index edf6068..20cc658 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -81,7 +81,7 @@ class Controller implements IController { * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory) { - if (commandMap[noteName] == null) { + if (!hasCommand(noteName)) { view.registerObserver(noteName, new Observer(executeCommand, this)); } commandMap[noteName] = commandFactory; @@ -94,7 +94,7 @@ class Controller implements IController { * - Returns [bool] - whether an [ICommand] is currently registered for the given [noteName]. */ bool hasCommand(String noteName) { - return commandMap[noteName] != null; + return commandMap.containsKey(noteName); } /** From fabf4aa52bbe095a40d34617af08a5e63579f01d Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sat, 5 Aug 2023 13:11:14 +0300 Subject: [PATCH 04/21] Keyword new removed from code. --- example/Framework_Verify.dart | 4 +-- lib/src/core/Controller.dart | 6 ++-- lib/src/interfaces/IController.dart | 4 +-- lib/src/interfaces/IFacade.dart | 2 +- lib/src/patterns/facade/Facade.dart | 8 ++--- test/Test_Controller.dart | 20 +++++------ test/Test_Facade.dart | 52 ++++++++++++++--------------- test/Test_MacroCommand.dart | 14 ++++---- test/Test_Mediator.dart | 14 ++++---- test/Test_Model.dart | 10 +++--- test/Test_Notification.dart | 8 ++--- test/Test_Observer.dart | 16 ++++----- test/Test_Proxy.dart | 10 +++--- test/Test_SimpleCommand.dart | 10 +++--- test/Test_View.dart | 28 ++++++++-------- test/Unit_Tests.dart | 22 ++++++------ 16 files changed, 114 insertions(+), 114 deletions(-) diff --git a/example/Framework_Verify.dart b/example/Framework_Verify.dart index d972a54..58f93ce 100644 --- a/example/Framework_Verify.dart +++ b/example/Framework_Verify.dart @@ -29,7 +29,7 @@ class Framework_Verify { write("
  • Data point added '${dataPoint2}'.
  • "); // Register a Proxy to hold the data - mvc.IProxy proxy = new mvc.Proxy(proxyName, dataObject); + mvc.IProxy proxy = mvc.Proxy(proxyName, dataObject); write("
  • Proxy '${proxyName}' created with for Data Object.
  • "); facade.registerProxy(proxy); write("
  • Proxy '${proxyName}' registered with Model, via Facade.
  • "); @@ -71,5 +71,5 @@ class Framework_Verify { } void main() { - new Framework_Verify().verify(); + Framework_Verify().verify(); } diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index 20cc658..fa921ac 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -9,7 +9,7 @@ part of puremvc; * * - Remembering which [ICommand]s are intended to handle which [INotification]s. * - Registering itself as an [IObserver] with the [View] for each [INotification] that it has an [ICommand] mapping for. - * - Creating a new instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. + * - Creating a instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. * - Calling the [ICommand]'s [execute] method, passing in the [INotification]. * * See [INotification], [ICommand] @@ -78,11 +78,11 @@ class Controller implements IController { * Register an [INotification] to [ICommand] mapping with the [Controller]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory) { if (!hasCommand(noteName)) { - view.registerObserver(noteName, new Observer(executeCommand, this)); + view.registerObserver(noteName, Observer(executeCommand, this)); } commandMap[noteName] = commandFactory; } diff --git a/lib/src/interfaces/IController.dart b/lib/src/interfaces/IController.dart index 53b0fca..bf8d16f 100644 --- a/lib/src/interfaces/IController.dart +++ b/lib/src/interfaces/IController.dart @@ -9,7 +9,7 @@ part of puremvc; * * - Remembering which [ICommand]s are intended to handle which [INotification]s. * - Registering itself as an [IObserver] with the [View] for each [INotification] that it has an [ICommand] mapping for. - * - Creating a new instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. + * - Creating a instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. * - Calling the [ICommand]'s [execute] method, passing in the [INotification]. * * See [INotification], [ICommand] @@ -19,7 +19,7 @@ abstract class IController { * Register an [INotification] to [ICommand] mapping with the [IController]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a instance of the [ICommand]. */ void registerCommand(String notificationName, Function commandFactory); diff --git a/lib/src/interfaces/IFacade.dart b/lib/src/interfaces/IFacade.dart index dce4583..995b4e6 100644 --- a/lib/src/interfaces/IFacade.dart +++ b/lib/src/interfaces/IFacade.dart @@ -58,7 +58,7 @@ abstract class IFacade extends INotifier { * Register an [INotification] to [ICommand] mapping with the [IController]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory); void executeCommand(String noteName, [dynamic body = null, String? type]); diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index a83a4ac..6e35f65 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -62,7 +62,7 @@ class Facade implements IFacade { if (instanceMap.containsKey(key)) { return instanceMap[key]; } else { - return instanceMap[key] = new Facade(key); + return instanceMap[key] = Facade(key); } } @@ -106,14 +106,14 @@ class Facade implements IFacade { * Register an [INotification] to [ICommand] mapping with the [Controller]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory) { controller!.registerCommand(noteName, commandFactory); } void executeCommand(String name, [dynamic body = null, String? type]) { - controller!.executeCommand(new Notification(name, body, type)); + controller!.executeCommand(Notification(name, body, type)); } /** @@ -237,7 +237,7 @@ class Facade implements IFacade { * - Param [type] - the type of the note (optional) */ void sendNotification(String noteName, [dynamic body, String? type]) { - notifyObservers(new Notification(noteName, body, type)); + notifyObservers(Notification(noteName, body, type)); } /** diff --git a/test/Test_Controller.dart b/test/Test_Controller.dart index 4744e34..e797f1f 100644 --- a/test/Test_Controller.dart +++ b/test/Test_Controller.dart @@ -25,7 +25,7 @@ class Test_Controller { // Register a Command String noteName = "ControllerTest2Note"; - controller.registerCommand(noteName, () => new ControllerTestMacroCommand()); + controller.registerCommand(noteName, () => ControllerTestMacroCommand()); // Make sure it's registered expect(controller.hasCommand(noteName), isTrue); @@ -38,11 +38,11 @@ class Test_Controller { // Register a Command String noteName = "ControllerTest3Note"; - controller.registerCommand(noteName, () => new ControllerTestDoubleInputCommand()); + controller.registerCommand(noteName, () => ControllerTestDoubleInputCommand()); // Create a Notification - ControllerTestVO vo = new ControllerTestVO(5); - mvc.INotification note = new mvc.Notification(noteName, vo); + ControllerTestVO vo = ControllerTestVO(5); + mvc.INotification note = mvc.Notification(noteName, vo); // Have the Controller execute the Command controller.executeCommand(note); @@ -59,11 +59,11 @@ class Test_Controller { // Register a Command String noteName = "ControllerTest4Note"; - controller.registerCommand(noteName, () => new ControllerTestMacroCommand()); + controller.registerCommand(noteName, () => ControllerTestMacroCommand()); // Create a Notification - ControllerTestVO vo = new ControllerTestVO(5); - mvc.INotification note = new mvc.Notification(noteName, vo); + ControllerTestVO vo = ControllerTestVO(5); + mvc.INotification note = mvc.Notification(noteName, vo); // Have the Controller execute the Command controller.executeCommand(note); @@ -80,7 +80,7 @@ class Test_Controller { // Register a Command String noteName = "ControllerTest5Note"; - controller.registerCommand(noteName, () => new ControllerTestMacroCommand()); + controller.registerCommand(noteName, () => ControllerTestMacroCommand()); // Make sure it's registered expect(controller.hasCommand(noteName), isTrue); @@ -110,8 +110,8 @@ class ControllerTestVO { class ControllerTestMacroCommand extends mvc.MacroCommand { void initializeMacroCommand() { // add the subcommands - addSubCommand(() => new ControllerTestDoubleInputCommand()); - addSubCommand(() => new ControllerTestSquareInputCommand()); + addSubCommand(() => ControllerTestDoubleInputCommand()); + addSubCommand(() => ControllerTestSquareInputCommand()); } } diff --git a/test/Test_Facade.dart b/test/Test_Facade.dart index 1867606..90c1879 100644 --- a/test/Test_Facade.dart +++ b/test/Test_Facade.dart @@ -77,7 +77,7 @@ class Test_Facade { // Register a Command String noteName = "FacadeTest2Note"; - facade.registerCommand(noteName, () => new FacadeTestMacroCommand()); + facade.registerCommand(noteName, () => FacadeTestMacroCommand()); // Make sure it's registered expect(facade.hasCommand(noteName), isTrue); @@ -90,10 +90,10 @@ class Test_Facade { // Register a Command String noteName = "FacadeTest3Note"; - facade.registerCommand(noteName, () => new FacadeTestDoubleInputCommand()); + facade.registerCommand(noteName, () => FacadeTestDoubleInputCommand()); // Create a value object - FacadeTestVO vo = new FacadeTestVO(5); + FacadeTestVO vo = FacadeTestVO(5); // Have the Facade send the note, triggering the Command facade.sendNotification(noteName, vo); @@ -110,10 +110,10 @@ class Test_Facade { // Register a Command String noteName = "FacadeTest4Note"; - facade.registerCommand(noteName, () => new FacadeTestMacroCommand()); + facade.registerCommand(noteName, () => FacadeTestMacroCommand()); // Create a value object - FacadeTestVO vo = new FacadeTestVO(5); + FacadeTestVO vo = FacadeTestVO(5); // Have the Facade execute the Command facade.sendNotification(noteName, vo); @@ -130,7 +130,7 @@ class Test_Facade { // Register a Command String noteName = "FacadeTest5Note"; - facade.registerCommand(noteName, () => new FacadeTestMacroCommand()); + facade.registerCommand(noteName, () => FacadeTestMacroCommand()); // Make sure it's registered expect(facade.hasCommand(noteName), isTrue); @@ -152,7 +152,7 @@ class Test_Facade { // Register a Mediator String mediatorName = "FacadeTest6Mediator"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); facade.registerMediator(mediator); // Make sure it's registered @@ -166,7 +166,7 @@ class Test_Facade { // Register a Mediator String mediatorName = "FacadeTest7Mediator"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); facade.registerMediator(mediator); // Make sure same mediator is retrieved @@ -180,7 +180,7 @@ class Test_Facade { // Register a Mediator String mediatorName = "FacadeTest8Mediator"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); facade.registerMediator(mediator); // Make sure it's registered @@ -201,11 +201,11 @@ class Test_Facade { // Register an Observer using this test // instance's facadeTestMethod as the callback String noteName = "FacadeTest8Note"; - mvc.IObserver observer = new mvc.Observer(facadeTestMethod, this); + mvc.IObserver observer = mvc.Observer(facadeTestMethod, this); facade.registerObserver(noteName, observer); // Create a notification - mvc.INotification note = new mvc.Notification(noteName); + mvc.INotification note = mvc.Notification(noteName); // Have the Facade notify the Observer facade.notifyObservers(note); @@ -220,10 +220,10 @@ class Test_Facade { final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component - FacadeTestViewComponent vc = new FacadeTestViewComponent(); + FacadeTestViewComponent vc = FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator(vc); + mvc.IMediator mediator = FacadeTestMediator(vc); facade.registerMediator(mediator); // Make sure it's registered @@ -239,10 +239,10 @@ class Test_Facade { final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component - FacadeTestViewComponent vc = new FacadeTestViewComponent(); + FacadeTestViewComponent vc = FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator(vc); + mvc.IMediator mediator = FacadeTestMediator(vc); facade.registerMediator(mediator); // Make sure it's registered @@ -261,10 +261,10 @@ class Test_Facade { final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component - FacadeTestViewComponent vc = new FacadeTestViewComponent(); + FacadeTestViewComponent vc = FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator(vc); + mvc.IMediator mediator = FacadeTestMediator(vc); facade.registerMediator(mediator); // Make sure the Mediator's listNotificationInterests() method was called @@ -277,10 +277,10 @@ class Test_Facade { final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Create a view component - FacadeTestViewComponent vc = new FacadeTestViewComponent(); + FacadeTestViewComponent vc = FacadeTestViewComponent(); // Register a FacadeTestMediator - mvc.IMediator mediator = new FacadeTestMediator(vc); + mvc.IMediator mediator = FacadeTestMediator(vc); facade.registerMediator(mediator); // Send the Notification @@ -300,7 +300,7 @@ class Test_Facade { // Register a Proxy String proxyName = "FacadeTest13Proxy"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); facade.registerProxy(proxy); // Make sure it's there @@ -314,7 +314,7 @@ class Test_Facade { // Register a Proxy String proxyName = "FacadeTest14Proxy"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); facade.registerProxy(proxy); // Make sure same Proxy is retrieved @@ -328,7 +328,7 @@ class Test_Facade { // Register a Proxy String proxyName = "FacadeTest15Proxy"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); facade.registerProxy(proxy); // Make sure it is returned when removed @@ -344,7 +344,7 @@ class Test_Facade { final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy - mvc.IProxy proxy = new FacadeTestProxy(); + mvc.IProxy proxy = FacadeTestProxy(); facade.registerProxy(proxy); // Make sure the Proxy's onRegister() method is called @@ -357,7 +357,7 @@ class Test_Facade { final facade = mvc.Facade.getInstance(multitonKey) as mvc.IFacade; // Register a Proxy - mvc.IProxy proxy = new FacadeTestProxy(); + mvc.IProxy proxy = FacadeTestProxy(); facade.registerProxy(proxy); // Remove the Proxy @@ -462,8 +462,8 @@ class FacadeTestVO { class FacadeTestMacroCommand extends mvc.MacroCommand { void initializeMacroCommand() { // add the subcommands - addSubCommand(() => new FacadeTestDoubleInputCommand()); - addSubCommand(() => new FacadeTestSquareInputCommand()); + addSubCommand(() => FacadeTestDoubleInputCommand()); + addSubCommand(() => FacadeTestSquareInputCommand()); } } diff --git a/test/Test_MacroCommand.dart b/test/Test_MacroCommand.dart index 5272411..4a43b4c 100644 --- a/test/Test_MacroCommand.dart +++ b/test/Test_MacroCommand.dart @@ -5,17 +5,17 @@ class Test_MacroCommand { group('MacroCommand', () { test('Constructor', () { // Create a MacroCommand - mvc.ICommand macroCommand = new MacroCommandTestCommand(); + mvc.ICommand macroCommand = MacroCommandTestCommand(); expect(macroCommand, isNotNull); }); test('execute()', () { // Create a MacroCommand - mvc.ICommand macroCommand = new MacroCommandTestCommand(); + mvc.ICommand macroCommand = MacroCommandTestCommand(); // Create a VO and a Notification to pass it to the Command with - MacroCommandTestVO vo = new MacroCommandTestVO(5); - mvc.INotification note = new mvc.Notification("MacroCommandTest", vo); + MacroCommandTestVO vo = MacroCommandTestVO(5); + mvc.INotification note = mvc.Notification("MacroCommandTest", vo); // Execute the MacroCommand execute the note macroCommand.execute(note); @@ -25,7 +25,7 @@ class Test_MacroCommand { test('initializeNotifier()', () { // Create a MacroCommand - mvc.INotifier notifier = new MacroCommandTestCommand(); + mvc.INotifier notifier = MacroCommandTestCommand(); // Call initializeNotifier() String multitonKey = "MacroCommandTest"; @@ -53,8 +53,8 @@ class MacroCommandTestVO { class MacroCommandTestCommand extends mvc.MacroCommand { void initializeMacroCommand() { // Add the subcommands - addSubCommand(() => new MacroCommandTestDoubleInputCommand()); - addSubCommand(() => new MacroCommandTestSquareInputCommand()); + addSubCommand(() => MacroCommandTestDoubleInputCommand()); + addSubCommand(() => MacroCommandTestSquareInputCommand()); } } diff --git a/test/Test_Mediator.dart b/test/Test_Mediator.dart index d1d7e5f..b217451 100644 --- a/test/Test_Mediator.dart +++ b/test/Test_Mediator.dart @@ -6,7 +6,7 @@ class Test_Mediator { test('Constructor', () { // Create a Mediator String mediatorName = "TestMediator1"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); // Make sure it was created expect(mediator, isNotNull); @@ -15,7 +15,7 @@ class Test_Mediator { test('getMediatorName()', () { // Create a Mediator String mediatorName = "TestMediator2"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); // Make sure the Mediator's name was set expect(mediator.getName(), equals(mediatorName)); @@ -24,11 +24,11 @@ class Test_Mediator { test('Constructor +viewComponent, getViewComponent(), .viewComponent', () { // Create a view component - Object viewComponent = new Object(); + Object viewComponent = Object(); // Create a Mediator with the view component String mediatorName = "TestMediator3"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName, viewComponent); + mvc.IMediator mediator = mvc.Mediator(mediatorName, viewComponent); // Make sure the view component was set expect(mediator.getViewComponent(), same(viewComponent)); @@ -37,11 +37,11 @@ class Test_Mediator { test('setViewComponent(), getViewComponent()', () { // Create a view component - Object viewComponent = new Object(); + Object viewComponent = Object(); // Create a Mediator String mediatorName = "TestMediator4"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); // Call setViewComponent() mediator.setViewComponent(viewComponent); @@ -54,7 +54,7 @@ class Test_Mediator { test('initializeNotifier()', () { // Create a Mediator String mediatorName = "TestMediator5"; - mvc.INotifier notifier = new mvc.Mediator(mediatorName); + mvc.INotifier notifier = mvc.Mediator(mediatorName); // Call initializeNotifier() String multitonKey = "MediatorTestKey"; diff --git a/test/Test_Model.dart b/test/Test_Model.dart index 80dbbc8..9ae629c 100644 --- a/test/Test_Model.dart +++ b/test/Test_Model.dart @@ -21,7 +21,7 @@ class Test_Model { // Register a Proxy String proxyName = "ModelTest2Proxy"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); model.registerProxy(proxy); // Make sure it's there @@ -35,7 +35,7 @@ class Test_Model { // Register a Proxy String proxyName = "ModelTest3Proxy"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); model.registerProxy(proxy); // Make sure same Proxy is retrieved @@ -49,7 +49,7 @@ class Test_Model { // Register a Proxy String proxyName = "ModelTest4Proxy"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); model.registerProxy(proxy); // Make sure it is returned when removed @@ -65,7 +65,7 @@ class Test_Model { final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy - mvc.IProxy proxy = new ModelTestProxy(); + mvc.IProxy proxy = ModelTestProxy(); model.registerProxy(proxy); // Make sure the Model calls the Proxy's onRegister() method @@ -78,7 +78,7 @@ class Test_Model { final model = mvc.Model.getInstance(multitonKey) as mvc.IModel; // Register a Proxy - mvc.IProxy proxy = new ModelTestProxy(); + mvc.IProxy proxy = ModelTestProxy(); model.registerProxy(proxy); // Remove the Proxy diff --git a/test/Test_Notification.dart b/test/Test_Notification.dart index b0bf266..1868a07 100644 --- a/test/Test_Notification.dart +++ b/test/Test_Notification.dart @@ -6,7 +6,7 @@ class Test_Notification { test('Constructor minimum args', () { // Create a Notification with a name only String name = "Test"; - mvc.INotification note = new mvc.Notification(name); + mvc.INotification note = mvc.Notification(name); // Make sure the note was created expect(note, isNotNull); @@ -15,7 +15,7 @@ class Test_Notification { test('.name, getName()', () { // Create a Notification with name only String name = "Test"; - mvc.INotification note = new mvc.Notification(name); + mvc.INotification note = mvc.Notification(name); // Make sure the name was set expect(name, equals(note.getName())); @@ -25,7 +25,7 @@ class Test_Notification { // Create a Notification with name and type only String name = "Test"; String type = "Type"; - mvc.INotification note = new mvc.Notification(name, null, type); + mvc.INotification note = mvc.Notification(name, null, type); // Make Sure the type was set expect(type, equals(note.getType())); @@ -35,7 +35,7 @@ class Test_Notification { // Create a Notification with a body String name = "Test"; List body = List.empty(growable: true); - mvc.INotification note = new mvc.Notification(name, body); + mvc.INotification note = mvc.Notification(name, body); // Make sure the body was set expect(body, equals(note.getBody())); diff --git a/test/Test_Observer.dart b/test/Test_Observer.dart index a2a0581..c59b52d 100644 --- a/test/Test_Observer.dart +++ b/test/Test_Observer.dart @@ -5,7 +5,7 @@ class Test_Observer { group('Observer', () { test('Constructor null args', () { // Create a blind Observer - mvc.IObserver observer = new mvc.Observer(() {}, null); + mvc.IObserver observer = mvc.Observer(() {}, null); // Make sure Observer was created expect(observer, isNotNull); @@ -13,7 +13,7 @@ class Test_Observer { test('Constructor complete args', () { // Create an observer with callback method and caller instance defined - mvc.IObserver observer = new mvc.Observer(this.observerTestMethod, this); + mvc.IObserver observer = mvc.Observer(this.observerTestMethod, this); // Make sure the Observer was created expect(observer, isNotNull); @@ -25,7 +25,7 @@ class Test_Observer { test('Constructor minimum args', () { // Create an Observer with callback only - mvc.IObserver observer = new mvc.Observer(this.observerTestMethod); + mvc.IObserver observer = mvc.Observer(this.observerTestMethod); // Make sure Observer was created expect(observer, isNotNull); @@ -36,7 +36,7 @@ class Test_Observer { test('setNotifyMethod()', () { // Create an Observer - mvc.IObserver observer = new mvc.Observer(null); + mvc.IObserver observer = mvc.Observer(null); // Call setNotifyMethod() observer.setNotifyMethod(observerTestMethod); @@ -47,7 +47,7 @@ class Test_Observer { test('setNotifyContext()', () { // Create an Observer - mvc.IObserver observer = new mvc.Observer(null); + mvc.IObserver observer = mvc.Observer(null); // Call setNotifyContext() observer.setNotifyContext(this); @@ -59,7 +59,7 @@ class Test_Observer { test('compareNotifyContext()', () { // Create an Observer with only a caller - mvc.IObserver observer = new mvc.Observer(null, this); + mvc.IObserver observer = mvc.Observer(null, this); // Make sure the caller was set expect(observer.compareNotifyContext(this), isTrue); @@ -67,11 +67,11 @@ class Test_Observer { test('notifyObserver()', () { // Create an Observer with this test instance's observerTestMethod() as the callback - mvc.IObserver observer = new mvc.Observer(this.observerTestMethod, this); + mvc.IObserver observer = mvc.Observer(this.observerTestMethod, this); // Create a Notification String name = "Test"; - mvc.INotification note = new mvc.Notification(name); + mvc.INotification note = mvc.Notification(name); // Notify the Observer observer.notifyObserver(note); diff --git a/test/Test_Proxy.dart b/test/Test_Proxy.dart index fc857d0..a3820e3 100644 --- a/test/Test_Proxy.dart +++ b/test/Test_Proxy.dart @@ -5,14 +5,14 @@ class Test_Proxy { group('ProxyTest', () { test('Constructor +name', () { String proxyName = "TestProxy1"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); expect(proxy, isNotNull); }); test('getName(), .name', () { // Create a Proxy String proxyName = "TestProxy2"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); // Make sure the Proxy name was set expect(proxy.getName(), equals(proxyName)); @@ -25,7 +25,7 @@ class Test_Proxy { // Create a Proxy with that data String proxyName = "TestProxy3"; - mvc.IProxy proxy = new mvc.Proxy(proxyName, data); + mvc.IProxy proxy = mvc.Proxy(proxyName, data); // Make sure the Proxy was created expect(proxy, isNotNull); @@ -41,7 +41,7 @@ class Test_Proxy { // Create a Proxy String proxyName = "TestProxy4"; - mvc.IProxy proxy = new mvc.Proxy(proxyName); + mvc.IProxy proxy = mvc.Proxy(proxyName); // Call setData() proxy.setData(data); @@ -54,7 +54,7 @@ class Test_Proxy { test('initializeNotifier()', () { // Create a Proxy String proxyName = "TestProxy5"; - mvc.INotifier notifier = new mvc.Proxy(proxyName); + mvc.INotifier notifier = mvc.Proxy(proxyName); // Call initializeNotifier() String multitonKey = "ProxyTestKey"; diff --git a/test/Test_SimpleCommand.dart b/test/Test_SimpleCommand.dart index 9744cf0..d92374c 100644 --- a/test/Test_SimpleCommand.dart +++ b/test/Test_SimpleCommand.dart @@ -5,17 +5,17 @@ class Test_SimpleCommand { group('SimpleCommand', () { test('Constructor', () { // Create a SimpleCommand - mvc.ICommand simpleCommand = new SimpleCommandTestDoubleInputCommand(); + mvc.ICommand simpleCommand = SimpleCommandTestDoubleInputCommand(); expect(simpleCommand, isNotNull); }); test('execute()', () { // Create a SimpleCommand - mvc.ICommand simpleCommand = new SimpleCommandTestDoubleInputCommand(); + mvc.ICommand simpleCommand = SimpleCommandTestDoubleInputCommand(); // Crete a VO and a Notification to pass it to the Command with - SimpleCommandTestVO vo = new SimpleCommandTestVO(5); - mvc.INotification note = new mvc.Notification("SimpleCommandTestNote", vo); + SimpleCommandTestVO vo = SimpleCommandTestVO(5); + mvc.INotification note = mvc.Notification("SimpleCommandTestNote", vo); // Execute the SimpleCommand with the note simpleCommand.execute(note); @@ -26,7 +26,7 @@ class Test_SimpleCommand { test('initializeNotifier()', () { // Create a SimpleCommand - mvc.INotifier notifier = new SimpleCommandTestDoubleInputCommand(); + mvc.INotifier notifier = SimpleCommandTestDoubleInputCommand(); // call initializeNotifier() String multitonKey = "SimpleCommandTest"; diff --git a/test/Test_View.dart b/test/Test_View.dart index aef71b9..cef8c55 100644 --- a/test/Test_View.dart +++ b/test/Test_View.dart @@ -25,7 +25,7 @@ class Test_View { // Register a Mediator String mediatorName = "ViewTest3Mediator"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); view.registerMediator(mediator); // Make sure it's registered @@ -39,7 +39,7 @@ class Test_View { // Register a Mediator String mediatorName = "ViewTest3Mediator"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); view.registerMediator(mediator); // Make sure same mediator is retrieved @@ -53,7 +53,7 @@ class Test_View { // Register a Mediator String mediatorName = "ViewTest4Mediator"; - mvc.IMediator mediator = new mvc.Mediator(mediatorName); + mvc.IMediator mediator = mvc.Mediator(mediatorName); view.registerMediator(mediator); // Make sure it's registered @@ -74,11 +74,11 @@ class Test_View { // Register an Observer using this test // instance's viewTestMethod as the callback String noteName = "ViewTest5Note"; - mvc.IObserver observer = new mvc.Observer(viewTestMethod, this); + mvc.IObserver observer = mvc.Observer(viewTestMethod, this); view.registerObserver(noteName, observer); // Create a notification - mvc.INotification note = new mvc.Notification(noteName); + mvc.INotification note = mvc.Notification(noteName); // Have the View notify the Observer view.notifyObservers(note); @@ -93,10 +93,10 @@ class Test_View { final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component - ViewTestViewComponent vc = new ViewTestViewComponent(); + ViewTestViewComponent vc = ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator(vc); + mvc.IMediator mediator = ViewTestMediator(vc); view.registerMediator(mediator); // Make sure it's registered @@ -112,10 +112,10 @@ class Test_View { final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component - ViewTestViewComponent vc = new ViewTestViewComponent(); + ViewTestViewComponent vc = ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator(vc); + mvc.IMediator mediator = ViewTestMediator(vc); view.registerMediator(mediator); // Make sure it's registered @@ -134,10 +134,10 @@ class Test_View { final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component - ViewTestViewComponent vc = new ViewTestViewComponent(); + ViewTestViewComponent vc = ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator(vc); + mvc.IMediator mediator = ViewTestMediator(vc); view.registerMediator(mediator); // Make sure the Mediator's listNotificationInterests() method was called @@ -150,14 +150,14 @@ class Test_View { final view = mvc.View.getInstance(multitonKey) as mvc.IView; // Create a view component - ViewTestViewComponent vc = new ViewTestViewComponent(); + ViewTestViewComponent vc = ViewTestViewComponent(); // Register a ViewTestMediator - mvc.IMediator mediator = new ViewTestMediator(vc); + mvc.IMediator mediator = ViewTestMediator(vc); view.registerMediator(mediator); // Create a Notification - mvc.INotification note = new mvc.Notification(ViewTestNotes.NOTE_2); + mvc.INotification note = mvc.Notification(ViewTestNotes.NOTE_2); // Send the Notification view.notifyObservers(note); diff --git a/test/Unit_Tests.dart b/test/Unit_Tests.dart index fa27902..3590793 100644 --- a/test/Unit_Tests.dart +++ b/test/Unit_Tests.dart @@ -34,16 +34,16 @@ class Unit_Tests { void run() { // Now, run the PureMVC Tests - new Test_Notification().run(); - new Test_Observer().run(); - new Test_SimpleCommand().run(); - new Test_MacroCommand().run(); - new Test_Proxy().run(); - new Test_Mediator().run(); - new Test_Model().run(); - new Test_View().run(); - new Test_Controller().run(); - new Test_Facade().run(); + Test_Notification().run(); + Test_Observer().run(); + Test_SimpleCommand().run(); + Test_MacroCommand().run(); + Test_Proxy().run(); + Test_Mediator().run(); + Test_Model().run(); + Test_View().run(); + Test_Controller().run(); + Test_Facade().run(); } } @@ -52,5 +52,5 @@ class Unit_Tests { */ void main() { // Unit test program, reporting for duty! - new Unit_Tests().run(); + Unit_Tests().run(); } From e40f5d20729c1e2aca735a88988a07fe900f7ce4 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:10:18 +0300 Subject: [PATCH 05/21] Setter for multitonKey returned back --- lib/src/core/Controller.dart | 1 + lib/src/core/Model.dart | 1 + lib/src/core/View.dart | 1 + lib/src/interfaces/IController.dart | 1 + lib/src/interfaces/IFacade.dart | 1 + lib/src/interfaces/IModel.dart | 1 + lib/src/interfaces/INotifier.dart | 1 + lib/src/interfaces/IView.dart | 1 + lib/src/patterns/facade/Facade.dart | 1 + lib/src/patterns/observer/Notifier.dart | 1 + 10 files changed, 10 insertions(+) diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index fa921ac..f2f2978 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -131,6 +131,7 @@ class Controller implements IController { // The Multiton Key for this Core late String _multitonKey; String get multitonKey => _multitonKey; + void set multitonKey(value) => _multitonKey = value; // Multiton instance map static Map instanceMap = Map(); diff --git a/lib/src/core/Model.dart b/lib/src/core/Model.dart index 5894bc2..03e287e 100644 --- a/lib/src/core/Model.dart +++ b/lib/src/core/Model.dart @@ -121,6 +121,7 @@ class Model implements IModel { // The Multiton Key for this Core late String _multitonKey; String get multitonKey => _multitonKey; + void set multitonKey(String value) => _multitonKey = value; } class MultitonErrorModelExists { diff --git a/lib/src/core/View.dart b/lib/src/core/View.dart index 308995d..2cb627a 100644 --- a/lib/src/core/View.dart +++ b/lib/src/core/View.dart @@ -233,6 +233,7 @@ class View implements IView { // The Multiton key for this Core late String _multitonKey; String get multitonKey => _multitonKey; + void set multitonKey(String value) => _multitonKey = value; } class MultitonErrorViewExists { diff --git a/lib/src/interfaces/IController.dart b/lib/src/interfaces/IController.dart index bf8d16f..f71eb2e 100644 --- a/lib/src/interfaces/IController.dart +++ b/lib/src/interfaces/IController.dart @@ -50,4 +50,5 @@ abstract class IController { * This IController's Multiton Key */ String get multitonKey; + void set multitonKey(String value); } diff --git a/lib/src/interfaces/IFacade.dart b/lib/src/interfaces/IFacade.dart index 995b4e6..a2144be 100644 --- a/lib/src/interfaces/IFacade.dart +++ b/lib/src/interfaces/IFacade.dart @@ -150,6 +150,7 @@ abstract class IFacade extends INotifier { * This [IFacade]'s Multiton key */ String? get multitonKey; + void set multitonKey(String? value); /** * This [IFacade]'s [IModel] diff --git a/lib/src/interfaces/IModel.dart b/lib/src/interfaces/IModel.dart index ef466b4..fd80093 100644 --- a/lib/src/interfaces/IModel.dart +++ b/lib/src/interfaces/IModel.dart @@ -54,4 +54,5 @@ abstract class IModel { * This [IModel]'s Multiton Key */ String get multitonKey; + void set multitonKey(String value); } diff --git a/lib/src/interfaces/INotifier.dart b/lib/src/interfaces/INotifier.dart index 70a9799..5908890 100644 --- a/lib/src/interfaces/INotifier.dart +++ b/lib/src/interfaces/INotifier.dart @@ -48,4 +48,5 @@ abstract class INotifier { * This INotifier's Multiton Key */ String? get multitonKey; + void set multitonKey(String? value); } diff --git a/lib/src/interfaces/IView.dart b/lib/src/interfaces/IView.dart index c624e37..500ea01 100644 --- a/lib/src/interfaces/IView.dart +++ b/lib/src/interfaces/IView.dart @@ -86,4 +86,5 @@ abstract class IView { * This [IView]'s Multiton key */ String get multitonKey; + void set multitonKey(String value); } diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index 6e35f65..82da9c9 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -320,6 +320,7 @@ class Facade implements IFacade { // This [IFacade]'s Multiton key String? _multitonKey; String? get multitonKey => _multitonKey; + void set multitonKey(String? value) => _multitonKey = value; // The [IFacade] Multiton instanceMap. static Map instanceMap = Map(); diff --git a/lib/src/patterns/observer/Notifier.dart b/lib/src/patterns/observer/Notifier.dart index ad17d91..2ae5125 100644 --- a/lib/src/patterns/observer/Notifier.dart +++ b/lib/src/patterns/observer/Notifier.dart @@ -73,6 +73,7 @@ class Notifier implements INotifier { // The Multiton Key for this app String? _multitonKey; String? get multitonKey => _multitonKey; + void set multitonKey(String? value) => _multitonKey = value; } class MultitonErrorNotifierLacksKey { From d34464848d1f4834e73f7751a5f2c236b87bf899 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:16:47 +0300 Subject: [PATCH 06/21] Keyword `new` returned to the comments in places where it was removed by auto-replace. --- lib/src/core/Controller.dart | 4 ++-- lib/src/interfaces/IController.dart | 4 ++-- lib/src/interfaces/IFacade.dart | 2 +- lib/src/patterns/facade/Facade.dart | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index f2f2978..a7cd0cf 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -9,7 +9,7 @@ part of puremvc; * * - Remembering which [ICommand]s are intended to handle which [INotification]s. * - Registering itself as an [IObserver] with the [View] for each [INotification] that it has an [ICommand] mapping for. - * - Creating a instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. + * - Creating a new instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. * - Calling the [ICommand]'s [execute] method, passing in the [INotification]. * * See [INotification], [ICommand] @@ -78,7 +78,7 @@ class Controller implements IController { * Register an [INotification] to [ICommand] mapping with the [Controller]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory) { if (!hasCommand(noteName)) { diff --git a/lib/src/interfaces/IController.dart b/lib/src/interfaces/IController.dart index f71eb2e..0a37ddf 100644 --- a/lib/src/interfaces/IController.dart +++ b/lib/src/interfaces/IController.dart @@ -9,7 +9,7 @@ part of puremvc; * * - Remembering which [ICommand]s are intended to handle which [INotification]s. * - Registering itself as an [IObserver] with the [View] for each [INotification] that it has an [ICommand] mapping for. - * - Creating a instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. + * - Creating a new instance of the proper [ICommand] to handle a given [INotification] when notified by the [IView]. * - Calling the [ICommand]'s [execute] method, passing in the [INotification]. * * See [INotification], [ICommand] @@ -19,7 +19,7 @@ abstract class IController { * Register an [INotification] to [ICommand] mapping with the [IController]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ void registerCommand(String notificationName, Function commandFactory); diff --git a/lib/src/interfaces/IFacade.dart b/lib/src/interfaces/IFacade.dart index a2144be..6e5efc3 100644 --- a/lib/src/interfaces/IFacade.dart +++ b/lib/src/interfaces/IFacade.dart @@ -58,7 +58,7 @@ abstract class IFacade extends INotifier { * Register an [INotification] to [ICommand] mapping with the [IController]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory); void executeCommand(String noteName, [dynamic body = null, String? type]); diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index 82da9c9..fb1afb3 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -106,7 +106,7 @@ class Facade implements IFacade { * Register an [INotification] to [ICommand] mapping with the [Controller]. * * - Param [noteName] - the name of the [INotification] to associate the [ICommand] with. - * - Param [commandFactory] - a function that creates a instance of the [ICommand]. + * - Param [commandFactory] - a function that creates a new instance of the [ICommand]. */ void registerCommand(String noteName, Function commandFactory) { controller!.registerCommand(noteName, commandFactory); From 2775755dbb1e1a1a947a22e0d8da7c963a38e3f6 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:32:27 +0300 Subject: [PATCH 07/21] Observer setter corrected - proper target for value - _notifyContext --- lib/src/patterns/observer/Observer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/patterns/observer/Observer.dart b/lib/src/patterns/observer/Observer.dart index fea04e9..adbfbb2 100644 --- a/lib/src/patterns/observer/Observer.dart +++ b/lib/src/patterns/observer/Observer.dart @@ -101,6 +101,6 @@ class Observer implements IObserver { } set notifyContext(Object? caller) { - notifyContext = caller; + _notifyContext = caller; } } From a1f0725c33f691e9fbc02e985e3a0e2b5556fbf4 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:41:59 +0300 Subject: [PATCH 08/21] Comments `parts` in Unit_Tests.dart rearranged to top. --- test/Unit_Tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Unit_Tests.dart b/test/Unit_Tests.dart index 3590793..433e758 100644 --- a/test/Unit_Tests.dart +++ b/test/Unit_Tests.dart @@ -9,12 +9,12 @@ import 'package:puremvc/puremvc.dart' as mvc; // The Unit Testing Framework for Dart import 'package:test/test.dart'; +// PureMVC Unit Tests part 'Test_Controller.dart'; part 'Test_Facade.dart'; part 'Test_MacroCommand.dart'; part 'Test_Mediator.dart'; part 'Test_Model.dart'; -// PureMVC Unit Tests part 'Test_Notification.dart'; part 'Test_Observer.dart'; part 'Test_Proxy.dart'; From f42377dfbceaca17553ca9fee88e76eb3600f4c5 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:44:56 +0300 Subject: [PATCH 09/21] Library 'dart:html' and related use of it removed from Unit_Tests as not needed for run of the tests. --- test/Unit_Tests.dart | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/Unit_Tests.dart b/test/Unit_Tests.dart index 433e758..a5e8314 100644 --- a/test/Unit_Tests.dart +++ b/test/Unit_Tests.dart @@ -1,9 +1,6 @@ // PureMVC Unit Test Library library puremvc_unit_tests; -// DART HTML Library -// import 'dart:html'; - // PureMVC Framework for Dart import 'package:puremvc/puremvc.dart' as mvc; // The Unit Testing Framework for Dart @@ -24,14 +21,6 @@ part 'Test_View.dart'; class Unit_Tests { Unit_Tests() {} - // void onTestResult(TestCase testCase) { - // write("${testCase.result} ${testCase.currentGroup}"); - // } - // - // void write(String message) { - // document.querySelector('#status')?.innerHtml = message; - // } - void run() { // Now, run the PureMVC Tests Test_Notification().run(); From 5457596f06fa9d4cad64ad12fef7e3e69575368d Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:50:59 +0300 Subject: [PATCH 10/21] Add access modifiers for `notifyContext` and `notifyMethod` in Observer --- lib/src/interfaces/IObserver.dart | 6 ++++++ lib/src/patterns/observer/Observer.dart | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/src/interfaces/IObserver.dart b/lib/src/interfaces/IObserver.dart index d793da9..e3f60a0 100644 --- a/lib/src/interfaces/IObserver.dart +++ b/lib/src/interfaces/IObserver.dart @@ -70,4 +70,10 @@ abstract class IObserver { * - Param [note] - the [INotification] to pass to the caller's [notifyMethod]. */ void notifyObserver(INotification note); + + Object? get notifyContext; + void set notifyContext(Object? value); + + Function? get notifyMethod; + set notifyMethod(Function? method); } diff --git a/lib/src/patterns/observer/Observer.dart b/lib/src/patterns/observer/Observer.dart index adbfbb2..db78611 100644 --- a/lib/src/patterns/observer/Observer.dart +++ b/lib/src/patterns/observer/Observer.dart @@ -100,7 +100,9 @@ class Observer implements IObserver { return identical(object, _notifyContext); } - set notifyContext(Object? caller) { - _notifyContext = caller; - } + Object? get notifyContext => _notifyContext; + set notifyContext(Object? caller) => _notifyContext = caller; + + Function? get notifyMethod => _notifyMethod; + set notifyMethod(Function? method) => _notifyMethod = method; } From 433aaac7ab261e88ec74390d1bff9ece6208fac1 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:54:21 +0300 Subject: [PATCH 11/21] Unnecessary comment on registerProxy in Model removed. --- lib/src/core/Model.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/core/Model.dart b/lib/src/core/Model.dart index 03e287e..329c28b 100644 --- a/lib/src/core/Model.dart +++ b/lib/src/core/Model.dart @@ -64,7 +64,6 @@ class Model implements IModel { * - Param [proxy] - an object reference to be held by the [IModel]. */ void registerProxy(IProxy proxy) { -// print("> Framework -> Model > registerProxy: " + proxy.getName()); proxy.initializeNotifier(multitonKey); proxyMap[proxy.getName()] = proxy; proxy.onRegister(); From f1c9c4ea84fc2728f88a76a1aacf3d7c12c8a06e Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 08:57:29 +0300 Subject: [PATCH 12/21] Initialize multitoneKey with constructor input value `key` through setter in View, Model and Controller. --- lib/src/core/Controller.dart | 2 +- lib/src/core/Model.dart | 2 +- lib/src/core/View.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index a7cd0cf..ae3b856 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -25,7 +25,7 @@ class Controller implements IController { */ Controller(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorControllerExists(); - _multitonKey = key; + multitonKey = key; instanceMap[_multitonKey] = this; commandMap = Map(); initializeController(); diff --git a/lib/src/core/Model.dart b/lib/src/core/Model.dart index 329c28b..8786dc1 100644 --- a/lib/src/core/Model.dart +++ b/lib/src/core/Model.dart @@ -30,7 +30,7 @@ class Model implements IModel { */ Model(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorModelExists(); - _multitonKey = key; + multitonKey = key; instanceMap[_multitonKey] = this; proxyMap = Map(); initializeModel(); diff --git a/lib/src/core/View.dart b/lib/src/core/View.dart index 2cb627a..e2067b9 100644 --- a/lib/src/core/View.dart +++ b/lib/src/core/View.dart @@ -25,7 +25,7 @@ class View implements IView { */ View(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorViewExists(); - _multitonKey = key; + multitonKey = key; instanceMap[_multitonKey] = this; mediatorMap = Map(); observerMap = Map>(); From eec1bd896ac3540c7c4853f30bdcd4258cc5611f Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:02:02 +0300 Subject: [PATCH 13/21] Revert back test on observer.notifyContext --- test/Test_Observer.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Test_Observer.dart b/test/Test_Observer.dart index c59b52d..b40f951 100644 --- a/test/Test_Observer.dart +++ b/test/Test_Observer.dart @@ -55,6 +55,7 @@ class Test_Observer { // Make sure caller was set expect(observer.getNotifyContext(), isNotNull); expect(observer.getNotifyContext(), same(this)); + expect(observer.notifyContext, isNotNull); }); test('compareNotifyContext()', () { From c8d0de428ef6360cbad1c863bf9546aa76acc7df Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:02:50 +0300 Subject: [PATCH 14/21] Corrections in comments - [_multitonKey] => [multitonKey] --- lib/src/core/Controller.dart | 2 +- lib/src/core/Model.dart | 2 +- lib/src/core/View.dart | 2 +- lib/src/interfaces/INotifier.dart | 2 +- lib/src/patterns/facade/Facade.dart | 4 ++-- lib/src/patterns/observer/Notifier.dart | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/core/Controller.dart b/lib/src/core/Controller.dart index ae3b856..2aee0b5 100644 --- a/lib/src/core/Controller.dart +++ b/lib/src/core/Controller.dart @@ -26,7 +26,7 @@ class Controller implements IController { Controller(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorControllerExists(); multitonKey = key; - instanceMap[_multitonKey] = this; + instanceMap[multitonKey] = this; commandMap = Map(); initializeController(); } diff --git a/lib/src/core/Model.dart b/lib/src/core/Model.dart index 8786dc1..7e0a08a 100644 --- a/lib/src/core/Model.dart +++ b/lib/src/core/Model.dart @@ -31,7 +31,7 @@ class Model implements IModel { Model(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorModelExists(); multitonKey = key; - instanceMap[_multitonKey] = this; + instanceMap[multitonKey] = this; proxyMap = Map(); initializeModel(); } diff --git a/lib/src/core/View.dart b/lib/src/core/View.dart index e2067b9..076a578 100644 --- a/lib/src/core/View.dart +++ b/lib/src/core/View.dart @@ -26,7 +26,7 @@ class View implements IView { View(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorViewExists(); multitonKey = key; - instanceMap[_multitonKey] = this; + instanceMap[multitonKey] = this; mediatorMap = Map(); observerMap = Map>(); initializeView(); diff --git a/lib/src/interfaces/INotifier.dart b/lib/src/interfaces/INotifier.dart index 5908890..98ed443 100644 --- a/lib/src/interfaces/INotifier.dart +++ b/lib/src/interfaces/INotifier.dart @@ -35,7 +35,7 @@ abstract class INotifier { /** * Initialize this [INotifier] instance. * - * This is how a [INotifier] gets its [_multitonKey]. + * This is how a [INotifier] gets its [multitonKey]. * Calls to [sendNotification] or access to the * [facade] will fail until after this method * has been called. diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index fb1afb3..7154d89 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -277,12 +277,12 @@ class Facade implements IFacade { /** * Initialize this [INotifier]. * - * This is how an [INotifier] gets its [_multitonKey]. + * This is how an [INotifier] gets its [multitonKey]. * Calls to [sendNotification] or to access the * [facade] will fail until after this method * has been called. * - * - Param [key] - the [_multitonKey] for this [INotifier] to use. + * - Param [key] - the [multitonKey] for this [INotifier] to use. */ void initializeNotifier(String? key) {} diff --git a/lib/src/patterns/observer/Notifier.dart b/lib/src/patterns/observer/Notifier.dart index 2ae5125..3f4d287 100644 --- a/lib/src/patterns/observer/Notifier.dart +++ b/lib/src/patterns/observer/Notifier.dart @@ -50,7 +50,7 @@ class Notifier implements INotifier { /** * Initialize this [INotifier] instance. * - * This is how a [INotifier] gets its [_multitonKey]. + * This is how a [INotifier] gets its [multitonKey]. * Calls to [sendNotification] or access to the * [facade] will fail until after this method * has been called. From f7220a0834ff2433b2f15f6d9f8ffc1c8658a8e0 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:07:00 +0300 Subject: [PATCH 15/21] Use getter for `multitonKey` when commandInstance.initializeNotifier (MacroCommand) --- lib/src/patterns/command/MacroCommand.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/patterns/command/MacroCommand.dart b/lib/src/patterns/command/MacroCommand.dart index 2493900..d1724c5 100644 --- a/lib/src/patterns/command/MacroCommand.dart +++ b/lib/src/patterns/command/MacroCommand.dart @@ -57,7 +57,7 @@ class MacroCommand extends Notifier implements ICommand { void execute(INotification note) { for (Function commandFactory in subCommands) { ICommand commandInstance = commandFactory(); - commandInstance.initializeNotifier(_multitonKey); + commandInstance.initializeNotifier(multitonKey); commandInstance.execute(note); } } From bf4cab24f541973bb67adfce8c0c45aae3b08607 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:08:50 +0300 Subject: [PATCH 16/21] Setting and accessing multitonKey from access modifiers in Facade constructor. --- lib/src/patterns/facade/Facade.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index 7154d89..3f3eb05 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -33,9 +33,9 @@ class Facade implements IFacade { */ Facade(String key) { if (instanceMap.containsKey(key)) throw MultitonErrorFacadeExists(); - _multitonKey = key; + multitonKey = key; initializeNotifier(key); - instanceMap[_multitonKey!] = this; + instanceMap[multitonKey!] = this; initializeFacade(); } From d14e870ca3917cc4b900c1f801daee34ed1dc777 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:10:32 +0300 Subject: [PATCH 17/21] Use access modifiers for multitonKey --- lib/src/patterns/facade/Facade.dart | 6 +++--- lib/src/patterns/observer/Notifier.dart | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/patterns/facade/Facade.dart b/lib/src/patterns/facade/Facade.dart index 3f3eb05..a20dd42 100644 --- a/lib/src/patterns/facade/Facade.dart +++ b/lib/src/patterns/facade/Facade.dart @@ -75,7 +75,7 @@ class Facade implements IFacade { */ void initializeController() { if (controller != null) return; - controller = Controller.getInstance(_multitonKey)!; + controller = Controller.getInstance(multitonKey)!; } /** @@ -87,7 +87,7 @@ class Facade implements IFacade { */ void initializeModel() { if (model != null) return; - model = Model.getInstance(_multitonKey)!; + model = Model.getInstance(multitonKey)!; } /** @@ -99,7 +99,7 @@ class Facade implements IFacade { */ void initializeView() { if (view != null) return; - view = View.getInstance(_multitonKey!); + view = View.getInstance(multitonKey!); } /** diff --git a/lib/src/patterns/observer/Notifier.dart b/lib/src/patterns/observer/Notifier.dart index 3f4d287..54119c2 100644 --- a/lib/src/patterns/observer/Notifier.dart +++ b/lib/src/patterns/observer/Notifier.dart @@ -66,8 +66,8 @@ class Notifier implements INotifier { * - Throws [MultitonErrorNotifierLacksKey] if no multitonKey is set. Usually means facade getter is being accessed before initializeNotifier has been called (i.e., from the constructor). Defer facade access until the onRegister method. */ IFacade get facade { - if (_multitonKey == null) throw MultitonErrorNotifierLacksKey(); - return Facade.getInstance(_multitonKey!)!; + if (multitonKey == null) throw MultitonErrorNotifierLacksKey(); + return Facade.getInstance(multitonKey!)!; } // The Multiton Key for this app From 1c829741081e1d1fa7757ffc3901aa49d879a990 Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:12:28 +0300 Subject: [PATCH 18/21] Open properties of Notification - name, body, type --- lib/src/patterns/observer/Notification.dart | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/patterns/observer/Notification.dart b/lib/src/patterns/observer/Notification.dart index d0f8a77..9d25532 100644 --- a/lib/src/patterns/observer/Notification.dart +++ b/lib/src/patterns/observer/Notification.dart @@ -23,11 +23,11 @@ class Notification implements INotification { /** * Constructor. * - * - Param [_name] - name of the [INotification]. - * - Param [_body] - the [INotification] body. (optional) - * - Param [_type] - the type of the [INotification] (optional) + * - Param [name] - name of the [INotification]. + * - Param [body] - the [INotification] body. (optional) + * - Param [type] - the type of the [INotification] (optional) */ - Notification(this._name, [dynamic this._body, this._type]) {} + Notification(this.name, [dynamic this.body, this.type]) {} /** * Get the [name] of the [INotification]. @@ -35,7 +35,7 @@ class Notification implements INotification { * - Returns [String] - the name of the [INotification]. */ String getName() { - return _name; + return name; } /** @@ -44,7 +44,7 @@ class Notification implements INotification { * - Param [body] - the body of the [INotification]. */ void setBody(dynamic bodyObject) { - _body = bodyObject; + body = bodyObject; } /** @@ -53,7 +53,7 @@ class Notification implements INotification { * - Returns [Dynamic] - the body of the [INotification]. */ dynamic getBody() { - return _body; + return body; } /** @@ -62,7 +62,7 @@ class Notification implements INotification { * - Param [type] - the type of the [INotification]. */ void setType(String? noteType) { - _type = noteType; + type = noteType; } /** @@ -71,21 +71,21 @@ class Notification implements INotification { * - Returns [String] - the type of the [INotification]. */ String? getType() { - return _type; + return type; } /** * This [INotifications]'s [name] */ - final String _name; + final String name; /** * This [INotifications]'s [type] */ - String? _type; + String? type; /** * This [INotifications]'s [body] */ - dynamic _body; + dynamic body; } From db0122bf00750db4f464fdf7940c9b41c74b4bbf Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:18:05 +0300 Subject: [PATCH 19/21] Comments added from previous versions of IObserver --- lib/src/interfaces/IObserver.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/interfaces/IObserver.dart b/lib/src/interfaces/IObserver.dart index e3f60a0..47b70c6 100644 --- a/lib/src/interfaces/IObserver.dart +++ b/lib/src/interfaces/IObserver.dart @@ -71,9 +71,15 @@ abstract class IObserver { */ void notifyObserver(INotification note); - Object? get notifyContext; + /** + * This [IObserver]'s [notifyMethod] (i.e., callback) + */ void set notifyContext(Object? value); + Object? get notifyContext; - Function? get notifyMethod; + /** + * This [IObserver]'s [notifyContext] (i.e., caller) + */ set notifyMethod(Function? method); + Function? get notifyMethod; } From 357356b274ec0837a76fd642ac5340ee0539407b Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:22:46 +0300 Subject: [PATCH 20/21] Return back tests for properties of observer: observer.notifyMethod and observer.notifyContext. --- test/Test_Observer.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Test_Observer.dart b/test/Test_Observer.dart index b40f951..dd058e5 100644 --- a/test/Test_Observer.dart +++ b/test/Test_Observer.dart @@ -20,7 +20,9 @@ class Test_Observer { // Make sure caller and callback were set expect(observer.getNotifyMethod(), isNotNull); + expect(observer.notifyMethod, isNotNull); expect(observer.getNotifyContext(), isNotNull); + expect(observer.notifyContext, isNotNull); }); test('Constructor minimum args', () { @@ -32,6 +34,7 @@ class Test_Observer { // Make sure callback method was set expect(observer.getNotifyMethod(), isNotNull); + expect(observer.notifyMethod, isNotNull); }); test('setNotifyMethod()', () { @@ -43,6 +46,7 @@ class Test_Observer { // Make sure callback method was set expect(observer.getNotifyMethod(), isNotNull); + expect(observer.notifyMethod, isNotNull); }); test('setNotifyContext()', () { From bdfd798e8afaef6151cc70bc5437e1eb876fe0ad Mon Sep 17 00:00:00 2001 From: Vladimir Minkin Date: Sun, 13 Aug 2023 09:43:02 +0300 Subject: [PATCH 21/21] README and VERSION update --- README.md | 6 +++--- VERSION | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 21b9574..5ac3715 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,14 @@ To use in your app, you can simply [add it to your project's pubspec.yaml as a d * [Reverse Text](https://github.com/PureMVC/puremvc-dart-demo-reversetext/wiki) ## Status -Production - [Version 2.0.6](https://github.com/PureMVC/puremvc-dart-multicore-framework/blob/master/VERSION) +Production - [Version 2.0.7](https://github.com/PureMVC/puremvc-dart-multicore-framework/blob/master/VERSION) ## Platforms / Technologies * [Google Dart](http://www.dartlang.org) ## License -* PureMVC MultiCore Framework for Dart (Ported) - Copyright © 2012-13 Cliff Hall -* PureMVC - Copyright © 2006-2013 [Futurescale, Inc](http://futurescale.com). +* PureMVC MultiCore Framework for Dart (Ported) - Copyright � 2012-13 Cliff Hall +* PureMVC - Copyright � 2006-2013 [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: diff --git a/VERSION b/VERSION index e75f3a3..292ab12 100644 --- a/VERSION +++ b/VERSION @@ -7,6 +7,15 @@ Release Date: 11/14/2013 Minor: 6 Authors: Cliff Hall -------------------------------------------------------------------------- +2.0.7 Update code base to match requirements of mull-safety and Dart SDK version > 3.0.0 + - environment: sdk: '^3.0.0' + - dependencies: + build_runner: any + build_web_compilers: any + Default Dart (Flutter) linter rules and code style corrections. + Many changes to internal processing of classes properties (through access modifiers). + Tests corrections to run unit tests and example. + 2.0.6 Update pubspec.yaml - environment: sdk: '>=0.8.10+6 <2.0.0' - dependencies: