@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
27 lines (26 loc) • 1.42 kB
JavaScript
import { objectAssign } from '../utils/lang/objectAssign';
import { clientAttributesDecoration } from './clientAttributesDecoration';
/**
* Decorator that binds a key to client methods
*
* @param client - sync client instance
* @param key - validated split key
*/
export function clientCSDecorator(log, client, key) {
var clientCS = clientAttributesDecoration(log, client);
return objectAssign(clientCS, {
// In the client-side API, we bind a key to the client `getTreatment*` and `track` methods
getTreatment: clientCS.getTreatment.bind(clientCS, key),
getTreatmentWithConfig: clientCS.getTreatmentWithConfig.bind(clientCS, key),
getTreatments: clientCS.getTreatments.bind(clientCS, key),
getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
getTreatmentsByFlagSets: clientCS.getTreatmentsByFlagSets.bind(clientCS, key),
getTreatmentsWithConfigByFlagSets: clientCS.getTreatmentsWithConfigByFlagSets.bind(clientCS, key),
getTreatmentsByFlagSet: clientCS.getTreatmentsByFlagSet.bind(clientCS, key),
getTreatmentsWithConfigByFlagSet: clientCS.getTreatmentsWithConfigByFlagSet.bind(clientCS, key),
track: clientCS.track.bind(clientCS, key),
// Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
isClientSide: true,
key: key
});
}