create account

Including JSON vs. TS by leprechaun

View this thread on: hive.blogpeakd.comecency.com
· @leprechaun · (edited)
$0.33
Including JSON vs. TS
I was looking into importing configurations in the proofofbrain.blog software.  

If I have a configuration set such as default night/day mode, is it determined at "compile time" (when I build the software and get it ready for use), or at start up time (when I actually start the server), or during runtime (it automatically reloads parameters on the go).

There are two short ways to load configuration files:
1. JSON file
2. A Type Script module file

A JSON file imports in each file that uses the constant like this:
```
import defaults from "../constants/site.json";
```
The JSON needs another file to describe the types of and which constants are set therein.  
![justin_campbell_zayydj9hjme_unsplash.jpg](https://images.ecency.com/DQmexZP33RrYPjrRQnoNuuEdQsmKuYT13bop8CTRBmghc5o/justin_campbell_zayydj9hjme_unsplash.jpg)


Photo by [Justin Campbell](https://unsplash.com/@justinhikestn?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/jason?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
  


The typescript approach is just export constants in a typescript file and then import them like this:
```
import { LIQUID_TOKEN_UPPERCASE } from "../client_config";
```


It turns out both the constants in the JSON and Typescript includes happen at "compile time."  So there is no advantage in one or the other in this sense.

If you use a configuration file, then you should be able to compile the typescript into finished software and then modify the configuration after the fact.  Or move the compiled software from a place that is configured for testing to another (with distinct configurations).  This is what I was hoping for with the JSON file.  Ideally, it should reload the JSON when there is a change.  It turns out this approach doesn't provide this as I hoped.  

It turns out you can have type safety in the JSON file, but you already get that by leaving it in a typescript file.  It seems like these should be variables that can be overridden with parameters set in a JSON file.  However, if the typescript exports various constants, you need to write lines of code for each constant.  The typescript needs to export a single export or the loading code will be ad-hoc.  Finally the front end will be unable to use something stored in a JSON file in the file system so anyway it seems we are stuck with compile time constants unless it is loaded from HTTPS.
👍  , , , , , , , , , , , , , , , ,
properties (23)
authorleprechaun
permlinkincluding-json-vs-ts
categoryhive-169321
json_metadata{"links":["https://unsplash.com/@justinhikestn?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText","https://unsplash.com/s/photos/jason?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText"],"image":["https://images.ecency.com/DQmexZP33RrYPjrRQnoNuuEdQsmKuYT13bop8CTRBmghc5o/justin_campbell_zayydj9hjme_unsplash.jpg"],"tags":["hive-169321","programming","typescript","json","ts","bluebrain"],"app":"localhost/3.0.18","format":"markdown+html"}
created2021-08-25 12:33:30
last_update2021-08-25 12:55:33
depth0
children2
last_payout2021-09-01 12:33:30
cashout_time1969-12-31 23:59:59
total_payout_value0.168 HBD
curator_payout_value0.164 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,454
author_reputation43,025,797,524,251
root_title"Including JSON vs. TS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,783,828
net_rshares405,631,464,788
author_curate_reward""
vote details (17)
@darkflame ·
This is really interesting to me. I want to learn how to script on <a href="https://developers.hive.io/">Hive</a>, so I am searching for and reviewing a lot of materials lately. Trying to go back to the basics (<a href="https://www.w3schools.com/whatis/whatis_json.asp">json</a>) I see how you were trying to get the two typescript and json to work together but did it not give you the desired result. Finding new ways to work around problems leads to creative solutions or at least attempts. I have built so many websites and they have all been thrown away, but now I use Hive and want to build web3 pages with tools and games. Your proofofbrain.blog front end is great! I appreciate how complex it is to modify and deploy. It's helpful to users like me to see the overall token breakdown, and how the top left icon takes you to <a href="https://www.proofofbrain.blog/created/hive-150329">POB</a> <- I love it! The landing page with the <a href="https://www.proofofbrain.blog/hive-150329/@leprechaun/the-absolute-beginner-s-guide-to-proof-of-brain">beginners guide</a> is a really good idea for new readers.
👍  
properties (23)
authordarkflame
permlinkre-leprechaun-qymcap
categoryhive-169321
json_metadata{"tags":["hive-169321"],"app":"peakd/2021.07.5"}
created2021-08-29 20:44:48
last_update2021-08-29 20:44:48
depth1
children0
last_payout2021-09-05 20:44:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,108
author_reputation91,308,866,075,809
root_title"Including JSON vs. TS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,878,978
net_rshares76,347,912
author_curate_reward""
vote details (1)
@gangstalking ·
Electronic-terrorism, voice to skull and neuro monitoring on Hive and Steem. You can ignore this, but your going to wish you didnt soon. This is happening whether you believe it or not. https://ecency.com/fyrstikken/@fairandbalanced/i-am-the-only-motherfucker-on-the-internet-pointing-to-a-direct-source-for-voice-to-skull-electronic-terrorism
👎  ,
properties (23)
authorgangstalking
permlinkre-leprechaun-including-json-vs-ts-20210825t123336815z
categoryhive-169321
json_metadata{"app":"hive-bot/0.6.3"}
created2021-08-25 12:33:39
last_update2021-08-25 12:33:39
depth1
children0
last_payout2021-09-01 12:33:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length343
author_reputation-67,597,107,868,724
root_title"Including JSON vs. TS"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,783,832
net_rshares-26,399,759,967
author_curate_reward""
vote details (2)