Skip to content

Commit

Permalink
$$$ update $$$
Browse files Browse the repository at this point in the history
  • Loading branch information
darekf77 committed Apr 27, 2024
1 parent eaef092 commit f28ab83
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ const UserContext = Firedev.createContext({
UserProvider,
}
});


const AppContext = Firedev.createContext({
remoteHost: `http://localhost:${HOST_BACKEND_PORT}`,
contexts: { UserContext },
});
//#endregion


Expand Down
18 changes: 15 additions & 3 deletions src/lib/base-classes/base-class.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { EndpointContext } from "../endpoint-context";
import { Symbols } from "../symbols";
import { inject } from '@angular/core';


export class BaseClass {
/**
* Current endpoint context
*/
get __endpoint_context__() {
return this[Symbols.ctxInClassOrClassObj] as EndpointContext;
}

/**
* Inject: Controllers, Providers, Repositories, Services, etc.
* TODO addd nest js injecting
*/
inject<T>(ctor: new (...args: any[]) => T): T {
return new Proxy({}, {
get: (_, propName) => {
const res = this.__endpoint_context__;
let instance: T = res.inject(ctor);
return typeof instance[propName] === 'function' ? instance[propName].bind(instance) : instance[propName];
const contextFromClass = ctor[Symbols.ctxInClassOrClassObj];
const resultContext = contextFromClass ? contextFromClass : this.__endpoint_context__;
if (resultContext) {
let instance: T = resultContext.inject(ctor);
return typeof instance[propName] === 'function' ? instance[propName].bind(instance) : instance[propName];
}
return inject(ctor)[propName];
},
}) as T;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export namespace Models {
export class ControllerConfig implements FiredevControllerOptions {
realtime?: boolean;
path: string;
className?: string;
className: string;
uniqueKey?: string;
classReference?: Function;
methods: { [methodName: string]: MethodConfig } = {};
Expand All @@ -117,7 +117,7 @@ export namespace Models {

//#region models / decorator abstract options
export interface DecoratorAbstractOpt {
className?: string;
className: string;
}
//#endregion

Expand Down

0 comments on commit f28ab83

Please sign in to comment.