overridable-fn 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["interface FnImpl<TArgs extends any[], TRet> {\n (...args: TArgs): TRet;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface FnImpl<TArgs extends any[], TRet> {\n (...args: TArgs): TRet;\n}\n\nexport interface WrappedFnImpl<TArgs extends any[], TRet> {\n (...args: TArgs): TRet;\n unwrap: () => FnImpl<TArgs, TRet>;\n override: (\n provideImpl: (curImpl: FnImpl<TArgs, TRet>) => FnImpl<TArgs, TRet>\n ) => {\n restore: () => void\n }\n}\n\nexport const fn = <TArgs extends any[], TRet>(\n defaultImpl: FnImpl<TArgs, TRet>\n): WrappedFnImpl<TArgs, TRet> => {\n let impl = defaultImpl;\n\n const unwrap = () => impl;\n\n const override = (\n provideImpl: (curImpl: FnImpl<TArgs, TRet>) => FnImpl<TArgs, TRet>\n ) => {\n const curImpl = impl\n impl = provideImpl(curImpl);\n const restore = () => {\n impl = curImpl\n }\n return { restore }\n };\n\n const invoker: WrappedFnImpl<TArgs, TRet> = (...args) => {\n return impl(...args);\n };\n\n invoker.unwrap = unwrap;\n invoker.override = override;\n\n return invoker;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,IAAM,KAAK,CACd,gBAC6B;AAC7B,MAAI,OAAO;AAEX,QAAM,SAAS,MAAM;AAErB,QAAM,WAAW,CACb,gBACC;AACD,UAAM,UAAU;AAChB,WAAO,YAAY,OAAO;AAC1B,UAAM,UAAU,MAAM;AAClB,aAAO;AAAA,IACX;AACA,WAAO,EAAE,QAAQ;AAAA,EACrB;AAEA,QAAM,UAAsC,IAAI,SAAS;AACrD,WAAO,KAAK,GAAG,IAAI;AAAA,EACvB;AAEA,UAAQ,SAAS;AACjB,UAAQ,WAAW;AAEnB,SAAO;AACX;","names":[]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["interface FnImpl<TArgs extends any[], TRet> {\n (...args: TArgs): TRet;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface FnImpl<TArgs extends any[], TRet> {\n (...args: TArgs): TRet;\n}\n\nexport interface WrappedFnImpl<TArgs extends any[], TRet> {\n (...args: TArgs): TRet;\n unwrap: () => FnImpl<TArgs, TRet>;\n override: (\n provideImpl: (curImpl: FnImpl<TArgs, TRet>) => FnImpl<TArgs, TRet>\n ) => {\n restore: () => void\n }\n}\n\nexport const fn = <TArgs extends any[], TRet>(\n defaultImpl: FnImpl<TArgs, TRet>\n): WrappedFnImpl<TArgs, TRet> => {\n let impl = defaultImpl;\n\n const unwrap = () => impl;\n\n const override = (\n provideImpl: (curImpl: FnImpl<TArgs, TRet>) => FnImpl<TArgs, TRet>\n ) => {\n const curImpl = impl\n impl = provideImpl(curImpl);\n const restore = () => {\n impl = curImpl\n }\n return { restore }\n };\n\n const invoker: WrappedFnImpl<TArgs, TRet> = (...args) => {\n return impl(...args);\n };\n\n invoker.unwrap = unwrap;\n invoker.override = override;\n\n return invoker;\n};\n"],"mappings":";AAcO,IAAM,KAAK,CACd,gBAC6B;AAC7B,MAAI,OAAO;AAEX,QAAM,SAAS,MAAM;AAErB,QAAM,WAAW,CACb,gBACC;AACD,UAAM,UAAU;AAChB,WAAO,YAAY,OAAO;AAC1B,UAAM,UAAU,MAAM;AAClB,aAAO;AAAA,IACX;AACA,WAAO,EAAE,QAAQ;AAAA,EACrB;AAEA,QAAM,UAAsC,IAAI,SAAS;AACrD,WAAO,KAAK,GAAG,IAAI;AAAA,EACvB;AAEA,UAAQ,SAAS;AACjB,UAAQ,WAAW;AAEnB,SAAO;AACX;","names":[]}
|
package/package.json
CHANGED