Comments (6)
Yes this would allow that. Till now I have just used a class with a "value" prop but this would allow any type.
from joist.
Could even put simple values in there?
const name = 'Grain';
const token = new InjectionToken(name); // would be nice to optionally give it a name
const providers = [{ provide: token, factory: () => 'Salt']
from joist.
One other note. Adding a default value would be optional. So this would be another way to require manually defending a provider.
from joist.
Found a minor issue with the new example in the readme (typescript is complaining), I hope this is related enough:
Type 'typeof Logger' is not assignable to type 'ProviderToken'.
Cannot assign an abstract constructor type to a non-abstract constructor type.ts(2322)
provider.d.ts(7, 5): The expected type comes from property 'provide' which is declared here on type 'Provider'
abstract class Logger {
abstract log(...args: any[]): void;
}
const app = new Injector([
{
provide: Logger as ProviderToken<Logger>, // manual typecast to supress
factory() {
return console;
}
}
]);
from joist.
I'll double check the example locally. There should be no need to type cast anything. I think I just have the Logger class those wrong.
from joist.
@Phoscur ah the problem with the docs is the abstract token. I thought I had added the ability to support abstract classes but turns out that is missing from the provider definition. I updated the docs to reflect the correct usage.
from joist.
Related Issues (20)
- Better test coverage of router
- Migrate from karma to web-test-runner
- Batch property changes
- Dev Tools HOT 1
- Dependency Dashboard
- @joist/di: lint rule for inject array not matching Injected types.
- @joist/di: implement lint fix to autofill injected services
- @joist/di: clear local cached instances on disconnect and connect
- SSR
- 3.0
- Example on how to use this toolkit with Lit HOT 10
- Cannot register element before dom renders with @attr
- Custom Element definition order matters HOT 4
- Allow for easier debug of dependency graph HOT 3
- Add option for inject to require a manually defined dependency. HOT 9
- Injector with parent Injector ignores its own providers for dependencies HOT 21
- Move Custom Element Injector logic to "element" package
- Function based API for StaticToken and Injector
- Docs refresh
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joist.