(name, dependencies, create, meta)
| 28 | * @returns {function} |
| 29 | */ |
| 30 | export function factory (name, dependencies, create, meta) { |
| 31 | function assertAndCreate (scope) { |
| 32 | // we only pass the requested dependencies to the factory function |
| 33 | // to prevent functions to rely on dependencies that are not explicitly |
| 34 | // requested. |
| 35 | const deps = pickShallow(scope, dependencies.map(stripOptionalNotation)) |
| 36 | |
| 37 | assertDependencies(name, dependencies, scope) |
| 38 | |
| 39 | return create(deps) |
| 40 | } |
| 41 | |
| 42 | assertAndCreate.isFactory = true |
| 43 | assertAndCreate.fn = name |
| 44 | assertAndCreate.dependencies = dependencies.slice().sort() |
| 45 | if (meta) { |
| 46 | assertAndCreate.meta = meta |
| 47 | } |
| 48 | |
| 49 | return assertAndCreate |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Sort all factories such that when loading in order, the dependencies are resolved. |
no test coverage detected
searching dependent graphs…