@tinkoff/dippy
Advanced tools
Comparing version 0.8.8 to 0.8.9
@@ -199,5 +199,6 @@ const Scope = { | ||
get(tokenORObject) { | ||
var _a; | ||
var _a, _b; | ||
let token; | ||
let optional = false; | ||
let multi = false; | ||
if (typeof tokenORObject === 'string') { | ||
@@ -209,2 +210,3 @@ token = tokenORObject; | ||
optional = tokenORObject.optional; | ||
multi = ((_a = token.options) === null || _a === void 0 ? void 0 : _a.multi) || false; | ||
} | ||
@@ -216,6 +218,11 @@ else { | ||
const record = this.getRecord(token); | ||
if (!record && ((_a = this.fallback) === null || _a === void 0 ? void 0 : _a.getRecord(token))) { | ||
if (!record && ((_b = this.fallback) === null || _b === void 0 ? void 0 : _b.getRecord(token))) { | ||
return this.fallback.get(tokenORObject); | ||
} | ||
if (!record && optional) { | ||
// return empty array for optional multi token | ||
if (multi) { | ||
return []; | ||
} | ||
// for legacy string tokens we cannot know if the token is multi or not | ||
return null; | ||
@@ -222,0 +229,0 @@ } |
@@ -203,5 +203,6 @@ 'use strict'; | ||
get(tokenORObject) { | ||
var _a; | ||
var _a, _b; | ||
let token; | ||
let optional = false; | ||
let multi = false; | ||
if (typeof tokenORObject === 'string') { | ||
@@ -213,2 +214,3 @@ token = tokenORObject; | ||
optional = tokenORObject.optional; | ||
multi = ((_a = token.options) === null || _a === void 0 ? void 0 : _a.multi) || false; | ||
} | ||
@@ -220,6 +222,11 @@ else { | ||
const record = this.getRecord(token); | ||
if (!record && ((_a = this.fallback) === null || _a === void 0 ? void 0 : _a.getRecord(token))) { | ||
if (!record && ((_b = this.fallback) === null || _b === void 0 ? void 0 : _b.getRecord(token))) { | ||
return this.fallback.get(tokenORObject); | ||
} | ||
if (!record && optional) { | ||
// return empty array for optional multi token | ||
if (multi) { | ||
return []; | ||
} | ||
// for legacy string tokens we cannot know if the token is multi or not | ||
return null; | ||
@@ -226,0 +233,0 @@ } |
{ | ||
"name": "@tinkoff/dippy", | ||
"version": "0.8.8", | ||
"version": "0.8.9", | ||
"initialVersion": "0.7.27", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -165,7 +165,7 @@ # @tinkoff/dippy | ||
// with special `optional` utility | ||
// string | null | ||
// `string` | `null` if not found | ||
const foo1 = container.get(optional(FOO_TOKEN)); | ||
// without `optional` utility | ||
// string | null | ||
// `string` | `null` if not found | ||
const foo2 = container.get({ token: FOO_TOKEN, optional: true }); | ||
@@ -183,2 +183,11 @@ ``` | ||
Multi optional token: | ||
```ts | ||
const LIST_TOKEN = createToken<{ key: string }>('list', { multi: true }); | ||
// `{ key: string }[]` | empty `[]` if not found | ||
const list = container.get(optional(LIST_TOKEN)); | ||
``` | ||
##### container.register(provider) | ||
@@ -185,0 +194,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65102
1392
411