0

In a React Native file:

import sjcl from './sjcl';
import './sha1x';

Functions in these files need access to each other. In particular, I'm trying to implement PBKDF2 according to this example. The author notes that I need to include both files. How can I give the functions within these files visibility to each other without modifying the files?

Community
  • 1
  • 1
Atte Juvonen
  • 4,922
  • 7
  • 46
  • 89
  • What do you mean by visibility? Does `sha1x` expect `sjcl` to be a global variable? Without modifying the files, globals are the only way to go. Even if you _could_ modify the files, circular dependencies are a problem. Are you sure you can't shape this like a tree? – salezica Dec 08 '16 at 17:13
  • `sha1x` defines functions within the `sjcl` namespace, for example `sjcl.hash.sha1`. It doesn't know what `sjcl` is and crashes. I don't know if it expects `sjcl` to be a global variable. – Atte Juvonen Dec 08 '16 at 17:17
  • If it says `sjcl.foo = bar`, and you don't want to put `import sjcl` on that file, the only possible way it can work is by making `sjcl` global (accessible from everywhere, always, like `String` or `Number`). I'm not sure how globals work on ReactNative (browser uses `window`, node uses `global`), Google must know – salezica Dec 08 '16 at 17:18

0 Answers0