Fork me on GitHub
#cljsrn
<
2020-01-20
>
Eric Ihli18:01:38

Still troubleshooting the issue mentioned above on Friday. I wanted to compare slurping and parsing the EDN to loading a raw json file. I have this in one of my cljs files. (defonce data (js/require "../../assets/test.json")) When I run npx react-native run-android, I get an error:

Loading dependency graph, done.
error SHA-1 for file /home/eihli/code/ezmonic-mobile/assets/test.json (/home/eihli/code/ezmonic-mobile/assets/test.json) is not computed. Run CLI with --verbose flag for more details.
ReferenceError: SHA-1 for file /home/eihli/code/ezmonic-mobile/assets/test.json (/home/eihli/code/ezmonic-mobile/assets/test.json) is not computed
    at DependencyGraph.getSha1 (/home/eihli/code/ezmonic-mobile/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:258:13) 

Eric Ihli18:01:41

I found an issue that mentioned a couple of fixes. https://github.com/facebook/metro/issues/330 One fix was to modify a file in metro. metro/src/node-haste/DependencyGraph.js#getSha1 . Since I'm not directly using metro but instead using it through react-native-cli, I didn't want to spend too much time learning the build process of both react-native-cli and metro so that I could build/test/use custom versions of each locally. Another fix was to put assets in a specific folder: ../../assets/asset.png as mentioned in that issue. I figured maybe that was the default assetRegistryPath mentioned https://facebook.github.io/metro/docs/en/configuration#assetexts. But I tried using that path as well as setting the assetRegistryPath in my metro.config.js and I continue to get the same error.

Eric Ihli19:01:10

Finally figured out the process of applying the change to DependencyGraph.js in that metro issue. It didn't work for me. Still getting the same error about SHA-1 for file...is not computed .

dotemacs19:01:01

@ericihli What about splitting the large EDN file that you’re trying to load and then loading those smaller files?

Eric Ihli19:01:37

I've considered it, but the overall time to parse wouldn't change and it would result in having to add async logic.

Eric Ihli19:01:17

And I can't think of a good way to split up the file where 1/x-th could be used independently of the other (n-1)/x-th.

Eric Ihli19:01:02

Well... not simply.

vikeri19:01:07

@ericihli we prebuild a SQLite file for a similar use case. But that requires SQLite though. One reason the performance can be different is that if you’re running with the debugger then the code is executed in Chrome instead of on the device. V8 vs. JSC plus that your workstation surely is more powerful than the average phone.

dotemacs19:01:00

I’ve just suggested this to him in a DM. Glad to hear that my idea is not so crazy after all.

Eric Ihli20:01:42

Thanks for the idea from both of you. I'm going to test it out and may end up using it if it's fast enough. But I still need to know how to require a json object. It has become personal. A quest to understand.

💪 4
vikeri20:01:26

Haha, I know the feeling

Eric Ihli20:01:25

Updating the getSha1 method as described in the github issue worked. I made a mistake in my initial attempt by editing DependencyGraph.js in the wrong package.

aw_yeah 4
vikeri20:01:06

Awesome, how fast did it load?

Eric Ihli20:01:56

Heh. I'll be lucky if I can answer that question by the end of the day. I just got it to build without error.