-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add flags for node modules, globals, and optional
closes #75
- Loading branch information
1 parent
8c01223
commit 32fa3d4
Showing
17 changed files
with
93 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { JpexInstance } from './types'; | ||
|
||
const clearCache = (jpex: JpexInstance, names?: any): any => { | ||
names = [].concat(names || []); | ||
for (const key in jpex.$$factories) { | ||
if (!names.length || names.indexOf(key) > -1) { | ||
jpex.$$factories[key].resolved = false; | ||
} | ||
} | ||
for (const key in jpex.$$resolved) { | ||
if (!names.length || names.indexOf(key) > -1) { | ||
delete jpex.$$resolved[key]; | ||
} | ||
} | ||
}; | ||
|
||
export default clearCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { JpexInstance, Dependency, AnyFunction } from './types'; | ||
import { extractParameters } from './utils'; | ||
import { allResolved, resolveDependencies } from './resolver'; | ||
|
||
const encase = ( | ||
jpex: JpexInstance, | ||
_deps: string[], | ||
_fn?: any, | ||
): any => { | ||
const [ dependencies, fn ] = ((): [ Dependency[], any ] => { | ||
if (typeof _deps === 'function') { | ||
return [ extractParameters(_deps), _deps ]; | ||
} | ||
return [ _deps, _fn ]; | ||
})(); | ||
let result: AnyFunction; | ||
|
||
const encased = function(...args: Parameters<any>) { | ||
/* eslint-disable no-invalid-this */ | ||
if (result && allResolved(jpex, dependencies)) { | ||
return result.apply(this, args); | ||
} | ||
const deps = resolveDependencies(jpex, { dependencies }); | ||
|
||
result = fn.apply(this, deps); | ||
|
||
return result.apply(this, args); | ||
/* eslint-enable */ | ||
}; | ||
encased.encased = fn; | ||
|
||
return encased; | ||
}; | ||
|
||
export default encase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters