Load Contexthub on conditional basis

Avatar

Avatar

yashaswidotiya

Avatar

yashaswidotiya

yashaswidotiya

19-05-2020

Hi All,

 

I want to load custom contexthub store on basis of some condition and for that, I have used apply method while registering the storeCandidate. The issue here is that I am getting "no suitable store Implementation found for ...." if condition fails. 

Is there any way that I can prevent these error from coming ?

Sample Code:- 

contextHub.Utils.storeCandidates.registerStoreCandidate(
"VariableName",
"contexthub.storeName",
0,

function(){return false};
);

 

Error message -- No suitable store implementation found for type: contexthub.storeName

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

BrianKasingli

MVP

Avatar

BrianKasingli

MVP

BrianKasingli
MVP

19-05-2020

@yashaswidotiya,

Sure, you can do this with a JavaScript condition block before you run the "registering the store candidate".

 

   function registerStoreCandidate() {
      if (canRegisterStoreCandidate()) {
        contextHub.Utils.storeCandidates.registerStoreCandidate(
        "VariableName",
        contexthub.storeName,
        0)
      }
   }

   function canRegisterStoreCandidate(){
     // ...someLogicReturnsBoolean;
     // example: returns true if window.contexthub && window.contexthub.storeName both are not empty or undefined.
     return window.contexthub && window.contexthub.storeName;
   };

 

 

 

Answers (0)