Skip to content

Commit 522172b

Browse files
author
Nikhil Thorat
authored
Wrap static methods in a function wrapper so the node io namespace routing works. (tensorflow#1507)
BUG <!-- Reviewable:start --> --- This change is [<img src="http://github.com/%3Ca%20href="https://reviewable.io/review_button.svg" rel="nofollow">https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/tensorflow/tfjs-core/1507) <!-- Reviewable:end -->
1 parent 0aa9e04 commit 522172b

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/io/io.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,11 @@ import {browserFiles} from './browser_files';
2424
import {browserHTTPRequest, isHTTPScheme} from './browser_http';
2525
import {concatenateArrayBuffers, decodeWeights, encodeWeights, getModelArtifactsInfoForJSON} from './io_utils';
2626
import {fromMemory, withSaveHandler} from './passthrough';
27-
import {IORouterRegistry} from './router_registry';
27+
import {getLoadHandlers, getSaveHandlers, registerLoadRouter, registerSaveRouter} from './router_registry';
2828
import {IOHandler, LoadHandler, ModelArtifacts, ModelStoreManager, SaveConfig, SaveHandler, SaveResult, WeightsManifestConfig, WeightsManifestEntry} from './types';
2929
import {loadWeights, weightsLoaderFactory} from './weights_loader';
3030

31-
const registerSaveRouter = IORouterRegistry.registerSaveRouter;
32-
const registerLoadRouter = IORouterRegistry.registerLoadRouter;
33-
const getSaveHandlers = IORouterRegistry.getSaveHandlers;
34-
const getLoadHandlers = IORouterRegistry.getLoadHandlers;
35-
3631
export {copyModel, listModels, moveModel, removeModel} from './model_management';
37-
3832
export {
3933
browserFiles,
4034
browserHTTPRequest,
@@ -56,8 +50,8 @@ export {
5650
SaveConfig,
5751
SaveHandler,
5852
SaveResult,
53+
weightsLoaderFactory,
5954
WeightsManifestConfig,
6055
WeightsManifestEntry,
61-
weightsLoaderFactory,
6256
withSaveHandler
6357
};

src/io/router_registry.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import {IOHandler} from './types';
1919

20-
export type IORouter = (url: string|string[], onProgress?: Function) => IOHandler;
20+
export type IORouter = (url: string|string[], onProgress?: Function) =>
21+
IOHandler;
2122

2223
export class IORouterRegistry {
2324
// Singleton instance.
@@ -79,13 +80,14 @@ export class IORouterRegistry {
7980
* @returns All valid handlers for `url`, given the currently registered
8081
* handler routers.
8182
*/
82-
static getLoadHandlers(url: string|string[],
83-
onProgress?: Function): IOHandler[] {
83+
static getLoadHandlers(url: string|string[], onProgress?: Function):
84+
IOHandler[] {
8485
return IORouterRegistry.getHandlers(url, 'load', onProgress);
8586
}
8687

87-
private static getHandlers(url: string|string[], handlerType: 'save'|'load',
88-
onProgress?: Function): IOHandler[] {
88+
private static getHandlers(
89+
url: string|string[], handlerType: 'save'|'load',
90+
onProgress?: Function): IOHandler[] {
8991
const validHandlers: IOHandler[] = [];
9092
const routers = handlerType === 'load' ? this.getInstance().loadRouters :
9193
this.getInstance().saveRouters;
@@ -98,3 +100,12 @@ export class IORouterRegistry {
98100
return validHandlers;
99101
}
100102
}
103+
104+
export const registerSaveRouter = (loudRouter: IORouter) =>
105+
IORouterRegistry.registerSaveRouter(loudRouter);
106+
export const registerLoadRouter = (loudRouter: IORouter) =>
107+
IORouterRegistry.registerLoadRouter(loudRouter);
108+
export const getSaveHandlers = (url: string|string[]) =>
109+
IORouterRegistry.getSaveHandlers(url);
110+
export const getLoadHandlers = (url: string|string[], onProgress?: Function) =>
111+
IORouterRegistry.getLoadHandlers(url);

0 commit comments

Comments
 (0)