Skip to content

Commit

Permalink
fix(di): removed initialization of dependencies of type providers aka…
Browse files Browse the repository at this point in the history
… classes before initialization all services are lazy loaded
  • Loading branch information
Stradivario committed Mar 7, 2024
1 parent 1627089 commit 279d29e
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 19 deletions.
3 changes: 2 additions & 1 deletion packages/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"test": "echo 'missing tests'",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "rm -rf dist && tsc"
Expand All @@ -32,4 +33,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "npx parcel ./examples/index.html --out-dir build/examples",
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"test": "echo 'missing tests'",
"clean": "git clean -dxf",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
Expand All @@ -30,4 +31,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/custom-attributes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "npx parcel ./examples/index.html --out-dir build/examples",
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"test": "echo 'missing tests'",
"clean": "git clean -dxf",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
Expand All @@ -26,4 +27,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/decorators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"test": "echo 'missing tests'",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "rm -rf dist && npx npx tsc"
Expand All @@ -26,4 +27,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
4 changes: 2 additions & 2 deletions packages/di/src/module/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('[Module]: tests', () => {
expect(test1.one).toBe(1);
});

it('Should automatically create new instance', async () => {
it('Should not inject provider when defined in module (lazy loading of providers feature)', async () => {
@Injectable()
class Test1 {}

Expand All @@ -75,7 +75,7 @@ describe('[Module]: tests', () => {
class MyModule {}

await Bootstrap(MyModule);
expect(has(Test1)).toBeTruthy();
expect(has(Test1)).toBeFalsy();
});

it('Should pass custom providers', async () => {
Expand Down
7 changes: 1 addition & 6 deletions packages/di/src/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ export const Module = <T>(

const providers = (entries.providers || []) as WithProviders[];
const factories = filterNonNull(providers).filter(v => !!v.useFactory);
const services = filterNonNull(providers).filter(v => !v.useFactory);


for (const entry of factories) {
ProvidersMetadata.set(entry, entry);
}

for (const entry of services) {
set(entry);
}

for (const entry of filterNonNull(
(entries.bootstrap || []) as ObjectUnion[]
Expand Down
3 changes: 2 additions & 1 deletion packages/experiments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"test": "echo 'missing tests'",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "rm -rf dist && tsc"
Expand All @@ -29,4 +30,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"lint": "npx eslint . --ext .ts",
"test": "echo 'missing tests'",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "cp ./libs/types ../../node_modules/@apollo/client/link/core/types.d.ts && rm -rf dist && tsc"
},
Expand All @@ -34,4 +35,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"test": "echo 'missing tests'",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "rm -rf dist && tsc"
Expand All @@ -28,4 +29,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/modifiers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"test": "echo 'missing tests'",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "rm -rf dist && npx tsc"
Expand All @@ -28,4 +29,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/operators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"clean": "git clean -dxf",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"test": "echo 'missing tests'",
"build": "rm -rf dist && tsc"
},
"repository": {
Expand All @@ -29,4 +30,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"test": "echo 'missing tests'",
"lint": "npx eslint . --ext .ts",
"lint-fix": "npx eslint . --fix --ext .ts",
"build": "rm -rf dist && tsc"
Expand All @@ -30,4 +31,4 @@
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"delete-dist": "rm -rf dist",
"clean": "git clean -dxf",
"lint": "echo LINT",
"test": "echo 'missing tests'",
"lint-fix": "echo LINT-FIX",
"lint-old": "npx eslint . --ext .ts || true",
"lint-fix-old": "npx eslint . --fix --ext .ts",
Expand All @@ -34,4 +35,4 @@
"module": "./dist/index.js",
"typings": "./dist/index.d.ts",
"schematics": "./collection.json"
}
}

0 comments on commit 279d29e

Please sign in to comment.