Skip to content

Commit

Permalink
adds a little more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Anderson committed Jun 30, 2020
1 parent d9eac03 commit 177bbca
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/privacy_compliance.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@ class PrivacyCompliance {
};
}

/**
* useConfig is a convenient way to pass configuration values to all frameworks.
* When a useConfig is called, every loaded framework will have their own
* useConfig methods called.
*
* The ideal pattern is to use keys to type the configs, for example:
* PrivacyCompliance.useConfig({
* usp: "1TFT"
* })
* Which could signal to any listening capabiltiy-frameworks to use the new
* US Privacy String
*
* @param {Object} someConfigs any config to share with all frameworks
*/
useConfig(someConfigs) {
this.frameworks.forEach(f => f.useConfig(someConfigs));
}

/**
* Allows this libraries internal logs to be accessible to including libraries.
* The default is to also insert any missed logs. Because this is setup as a singleton,
* it is easy to miss the initial setup logs, that happened, before a logger was setup.
*
* @param {Function} logFunction to be called everytime a new log entry is generated
* @param {Boolean} relogMissedEntries when true will relog missed entries from before the logger was wired up
*/
useLogger(logFunction, relogMissedEntries = true) {
this.logger = logFunction;
if (relogMissedEntries) {
Expand All @@ -35,27 +57,40 @@ class PrivacyCompliance {
this.logger(...args);
}

// For use with testing only
reset() {
this.frameworks = [];
this.supportedCapabilities = new Set();
}

addFramework(frameworkInstance) {
this.log('Adding new framework: ', frameworkInstance.name);
frameworkInstance.setPrivacyComplianceInstance(privacyComplianceSingleton);
this.frameworks.push(frameworkInstance);
frameworkInstance.supportedCapabilities().forEach(c => this.supportedCapabilities.add(c));
}

/**
* Checks if a given Capability (as a string) can be answered by the loaded
* frameworks.
*
* Caution: not all frameworks will be applicable and able to
* answer this capability for all environments.
*
* @param {String} capability the method name of the capability
* @returns Boolean true if the capability can be answered
*/
hasFrameworkLoadedToAnswerCapability(capability) {
return this.supportedCapabilities.has(capability);
}

/**
* Returns a list of applicable frameworks for this environment.
*/
applicableFrameworks() {
return this.frameworks.filter(f => f.isApplicable());
}

// For use with testing only
reset() {
this.frameworks = [];
this.supportedCapabilities = new Set();
}

/**
* This method will take a string, translate it into a method and call it
* on the added frameworks. If all applicable frameworks support this capability
Expand Down

0 comments on commit 177bbca

Please sign in to comment.