0

I am trying to build out a piece of code to display a modal, which is working well, however, I need the modal to call callbacks that are provided to it. I am currently using a session variable to display it, and I'm finding that I am unable to save a function as part of the variable. The other keys coma across fine.

I've tried using named functions, unnamed functions, setting the key to non-function values (Which works) setting other keys to functions (Which doesn't work)

Session.set('modal',{
  message: 'I am a modal!',
  confirm: 'I can see that.',
  deny: 'I disagree.',
  callback: ()=>{
    console.log('I'm glad we agree!!')
  }
})

console.log(Session.get('modal')) // {message:'I am a modal!', confirm:'I can see that.', deny:'I disagree.'}

I was expecting it to be fine, as Session's docs say any EJSON value can be saved, which, to my knowledge includes functions. Instead, it seems to just, not assign that key at all, it's not even undefined, It's just not there.

1 Answer 1

0

A viable workaround for me was to set a separate variable to the callback, and then set the session variable, then in the event handler, to call it from the separate variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.