Skip to content

Commit a157626

Browse files
committed
Add comments
1 parent 1bf1f71 commit a157626

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed
Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Copyright 2020, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,14 +15,71 @@
1515
*/
1616

1717
declare module '@optimizely/optimizely-sdk/lib/core/projet_config_manager' {
18-
import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config';
19-
interface ProjectConfigManager {
20-
getConfig(): ProjectConfig | null;
21-
onUpdate(): (listener: (config: ProjectConfig) => void) => () => void;
22-
onReady(): Promise<{ success: boolean; reason?: string }>;
23-
getOptimizelyConfig(): ProjectConfig | null;
24-
stop(): Promise<void> | void;
25-
}
26-
27-
export function ProjectConfigManager(config: ProjectConfig): ProjectConfigManager;
18+
import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config';
19+
20+
/**
21+
* ProjectConfigManager provides project config objects via its methods
22+
* getConfig and onUpdate. It uses a DatafileManager to fetch datafiles. It is
23+
* responsible for parsing and validating datafiles, and converting datafile
24+
* JSON objects into project config objects.
25+
* @param {ProjectConfig} config
26+
* @param {Object|string} config.datafile
27+
* @param {Object} config.datafileOptions
28+
* @param {Object} config.jsonSchemaValidator
29+
* @param {string} config.sdkKey
30+
*/
31+
export function ProjectConfigManager(config: ProjectConfig): ProjectConfigManager;
32+
33+
interface ProjectConfigManager {
34+
35+
/**
36+
* Returns the current project config object, or null if no project config object
37+
* is available
38+
* @return {ProjectConfig|null}
39+
*/
40+
getConfig(): ProjectConfig | null;
41+
42+
/**
43+
* Add a listener for project config updates. The listener will be called
44+
* whenever this instance has a new project config object available.
45+
* Returns a dispose function that removes the subscription
46+
* @param {Function} listener
47+
* @return {Function}
48+
*/
49+
onUpdate(): (listener: (config: ProjectConfig) => void) => () => void;
50+
51+
/**
52+
* Returns a Promise that fulfills when this ProjectConfigManager is ready to
53+
* use (meaning it has a valid project config object), or has failed to become
54+
* ready.
55+
*
56+
* Failure can be caused by the following:
57+
* - At least one of sdkKey or datafile is not provided in the constructor argument
58+
* - The provided datafile was invalid
59+
* - The datafile provided by the datafile manager was invalid
60+
* - The datafile manager failed to fetch a datafile
61+
*
62+
* The returned Promise is fulfilled with a result object containing these
63+
* properties:
64+
* - success (boolean): True if this instance is ready to use with a valid
65+
* project config object, or false if it failed to
66+
* become ready
67+
* - reason (string=): If success is false, this is a string property with
68+
* an explanatory message.
69+
* @return {Promise}
70+
*/
71+
onReady(): Promise<{ success: boolean; reason?: string }>;
72+
73+
/**
74+
* Returns the optimizely config object
75+
* @return {ProjectConfig}
76+
*/
77+
getOptimizelyConfig(): ProjectConfig;
78+
79+
/**
80+
* Stop the internal datafile manager and remove all update listeners
81+
* @return {Promise|void}
82+
*/
83+
stop(): Promise<void> | void;
84+
}
2885
}

0 commit comments

Comments
 (0)