Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
UIMSolutions committed Dec 27, 2024
1 parent 3c9722d commit 725a48f
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 58 deletions.
3 changes: 3 additions & 0 deletions apps/dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ dependency "vibe-d" version="~>0.10.0"
dependency "uim:core" path="../"
dependency "uim:oop" path="../"
dependency "uim:mvc" path="../"
dependency "uim:controllers" path="../"
dependency "uim:models" path="../"
dependency "uim:views" path="../"

sourcePaths "."
importPaths "."
Expand Down
85 changes: 52 additions & 33 deletions apps/uim/apps/classes/applications/application.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,76 @@ class DApplication : UIMObject, IApplication {
return false;
}

_controllers = new DControllerRegistry;
_controllerRegistry = new DControllerRegistry;
_modelRegistry = new DModelRegistry;
_viewRegistry = new DViewRegistry;

return true;
}

// #region controllers
protected DControllerRegistry _controllers;
IController[] controllers() {
return objects;
}

IController controller(string key) {
return _controllers.get(key, null);
}
IApplication controller(string key, IController newController) {
_controllers[key] = newController;
return this;
}
mixin(MixinRegistry!("Controller", "Controllers"));
unittest {
auto app = new DApplication;
writeln("Controllers length = ", app.controllers.length);
writeln("Singleton Controllers length = ", ControllerRegistry.length);

app.controller("test", new DController);
writeln("Controllers length = ", app.controllers.length);
writeln("Singleton Controllers length = ", ControllerRegistry.length);

ControllerRegistry.register("test", new DController);
ControllerRegistry.register("test1", new DController);
writeln("Controllers length = ", app.controllers.length);
writeln("Singleton Controllers length = ", ControllerRegistry.length);

app.removeController("test");
writeln("Controllers length = ", app.controllers.length);
writeln("Singleton Controllers length = ", ControllerRegistry.length);
}
// #endregion controllers

// #region models
protected IModel[string] _models;
IModel[string] models() {
return _models.dup;
}
mixin(MixinRegistry!("Model", "Models"));
unittest {
auto app = new DApplication;
writeln("Models length = ", app.models.length);
writeln("Singleton Models length = ", ModelRegistry.length);

IModel model(string key) {
return _models.get(key, null);
}
IApplication model(string key, IModel newModel) {
_models[key] = newModel;
return this;
app.model("test", new DModel);
writeln("Models length = ", app.models.length);
writeln("Singleton Models length = ", ModelRegistry.length);

ModelRegistry.register("test", new DModel);
ModelRegistry.register("test1", new DModel);
writeln("Models length = ", app.models.length);
writeln("Singleton Models length = ", ModelRegistry.length);

app.removeModel("test");
writeln("Models length = ", app.models.length);
writeln("Singleton Models length = ", ModelRegistry.length);
}
// #endregion models

// #region views
protected IView[string] _views;
IView[string] views() {
return _views.dup;
}
mixin(MixinRegistry!("View", "Views"));
unittest {
auto app = new DApplication;
writeln("Views length = ", app.views.length);
writeln("Singleton Views length = ", ViewRegistry.length);

IView view(string key) {
return _views.get(key, null);
}
IApplication view(string key, IView newView) {
_views[key] = newView;
return this;
app.view("test", new DView);
writeln("Views length = ", app.views.length);
writeln("Singleton Views length = ", ViewRegistry.length);

ViewRegistry.register("test", new DView);
ViewRegistry.register("test1", new DView);
writeln("Views length = ", app.views.length);
writeln("Singleton Views length = ", ViewRegistry.length);

app.removeView("test");
writeln("Views length = ", app.views.length);
writeln("Singleton Views length = ", ViewRegistry.length);
}
// #endregion views

Expand Down
6 changes: 3 additions & 3 deletions apps/uim/apps/interfaces/application.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import uim.apps;
@safe:
interface IApplication : INamed {
// #region controllers
IController[string] controllers();
IController[] controllers();

IController controller(string key);
IApplication controller(string key, IController newController);
// #endregion controllers

// #region models
IModel[string] models();
IModel[] models();

IModel model(string key);
IApplication model(string key, IModel newModel);
// #endregion models

// #region views
IView[string] views();
IView[] views();

IView view(string key);
IApplication view(string key, IView newView);
Expand Down
3 changes: 3 additions & 0 deletions apps/uim/apps/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public { // uim libraries
import uim.core;
import uim.oop;
import uim.mvc;
import uim.controllers;
import uim.models;
import uim.views;
}

public { // uim.filesystem libraries
Expand Down
2 changes: 1 addition & 1 deletion controllers/uim/controllers/classes/controllers/registry.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import uim.controllers;
class DControllerRegistry : DObjectRegistry!DController {
}

auto ControllerRegistry() {
auto ControllerRegistry() { // for Singleton
return DControllerRegistry.registry;
}
8 changes: 4 additions & 4 deletions dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"stdx-allocator": "2.77.5",
"taggedalgebraic": "0.11.23",
"unit-threaded": "2.1.9",
"vibe-container": "1.3.1",
"vibe-container": "1.4.0",
"vibe-core": "2.9.6",
"vibe-d": "0.10.1",
"vibe-http": "1.1.2",
"vibe-inet": "1.0.1",
"vibe-serialization": "1.0.6",
"vibe-http": "1.2.1",
"vibe-inet": "1.1.0",
"vibe-serialization": "1.0.7",
"vibe-stream": "1.1.1"
}
}
3 changes: 2 additions & 1 deletion oop/uim/oop/mixins/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public {
import uim.oop.mixins.configuration;
import uim.oop.mixins.conventions;
import uim.oop.mixins.cookiecrypt;
import uim.oop.mixins.data;
import uim.oop.mixins.element;
import uim.oop.mixins.exception;
import uim.oop.mixins.fileconfig;
import uim.oop.mixins.mergevariables;
import uim.oop.mixins.data;
import uim.oop.mixins.registry;
import uim.oop.mixins.staticconfig;
import uim.oop.mixins.valuemap;
}
Expand Down
33 changes: 17 additions & 16 deletions oop/uim/oop/mixins/registry.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import uim.oop;

@safe:

template TRegistry(T : UIMObject, R, M) {
R registry;

size_t length() {
return registry.length;
string mixinRegistry(string single, string plural) {
return "
protected D"~single~"Registry _"~single.toLower~"Registry;
I"~single~"[] "~plural.toLower~"() {
return _"~single.toLower~"Registry.objects.map!(c => cast(I"~single~")c).array;
}
T[] objects() {
return registry.objects;
I"~single~" "~single.toLower~"(string key) {
return cast(I"~single~")_"~single.toLower~"Registry.get(key);
}

T get(string key) {
return registry.get(key, null);
IApplication "~single.toLower~"(string key, I"~single~" new"~single~") {
_"~single.toLower~"Registry.register(key, cast(D"~single~")new"~single~");
return this;
}

M set(string key, IController newController) {
registry.set(key, newController);
return cast(M)this;
}

IApplication remove"~single~"(string key) {
_"~single.toLower~"Registry.removeKey(key);
return this;
}";
}
template MixinRegistry(string single, string plural) {
const char[] MixinRegistry = mixinRegistry(single, plural);
}
1 change: 1 addition & 0 deletions views/uim/views/classes/views/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module uim.views.classes.views;
public {
import uim.views.classes.views.view;
import uim.views.classes.views.factory;
import uim.views.classes.views.registry;
}
17 changes: 17 additions & 0 deletions views/uim/views/classes/views/registry.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/****************************************************************************************************************
* Copyright: © 2017-2024 Ozan Nurettin Süel (aka UIManufaktur) *
* License: Subject to the terms of the Apache 2.0 license, as written in the included LICENSE.txt file. *
* Authors: Ozan Nurettin Süel (aka UIManufaktur) *
*****************************************************************************************************************/
module uim.views.classes.views.registry;

import uim.views;

@safe:

class DViewRegistry : DObjectRegistry!DView {
}

auto ViewRegistry() { // for Singleton
return DViewRegistry.registry;
}

0 comments on commit 725a48f

Please sign in to comment.