-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage in a browser #1
Comments
Could you tell me a bit more about how you plan on using it so I can think about how loading from a string would fit in? |
The use case is simply examining the JSON in a handy way to make a run-time type check for data sent from server to client. In other words, there is no instantiation and no loading of modules should be required. That said, loading of modules is entirely possible if done through require(). Even e.g. 'fs' has its browserified version. Maybe this is outside the scope of tsreflect or maybe tsreflect could be split into two modules: one for sec JSON symbol inspection and another the more intelligent work (which is likely to differ between use cases anyway) |
The JSON declaration can include references and require statements. How would you see those being handled if the initial data was loaded directly via a string (or JSON)? |
My use case has a number of simplifications, but I can see how this could be implemented in general. First, the simple use case: Since the data is communicated through json over http, there are only interfaces, basic types, enums and arrays (and the orthogonal combination of these). Furthermore, I'm assuming that all type names are unique. Given that, I can just read in a bunch of .json files beforehand and find the types I need without complex dereferencing of require statements etc. However, I still think the general case can be handled if the JSON data included a "path" member for each JSON object. Then you could implement full-blown module loading semantics. Simply hand an array of all JSON 'files' to tsreflect. |
Are you just using the .d.json files directly? |
Yes I currently am. |
That’s probably the best thing to do. The tsreflect module is probably a bit heavyweight to use on the client anyways. |
I think you are right, that's why I was on about splitting tsreflect up into two modules. If one could split the search functions from the instantiation then users of tsreflect would become less dependent on the actual JSON format used since they would query the data with functions. This could then also include better require() resolving with path members. But maybe this is all getting out of scope. It seems we've reached an understanding. |
Great idea, tsreflect! We were just about to invent the wheel ourselves.
I'd like to use tsreflect in a browser with browserify. For that scenario, I'd have to be able to load JSON data from strings instead of from files/modules. Something to add maybe?
The text was updated successfully, but these errors were encountered: