Coder Social home page Coder Social logo

Comments (7)

elliotdickison avatar elliotdickison commented on May 29, 2024 1

Oh nice, love it. I think I've got enough to put together a PR, should have time in the next couple of weeks.

from react-native-ultimate-config.

elliotdickison avatar elliotdickison commented on May 29, 2024

@maxkomarychev Any feedback on this? I'd be happy to put together a PR if we can agree on a direction.

from react-native-ultimate-config.

maxkomarychev avatar maxkomarychev commented on May 29, 2024

hey! that's a great suggestion!

why not drop the js_override flag and the UltimateConfig module reference from JavaScript entirely and just generate a pure JavaScript module containing the needed variables. This would simplify usage (zero config!) and make things work on the web and on native with the same import path. Or am I missing some benefit to pulling the JS config values from native?

the very reason I created this project is to keep all platforms aligned. there are plenty of solutions which work good in pure js world but I want to be able to define variables in all platforms. having said that it seems natural to propagate values from ios/android to js.

it's getting a bit tricky now to try to retrofit pure-js solution on top of current library.
I wonder is it possible to have isomorphic implementation such that we don't have to generate separate d.ts file for overrides.

for instance is maybe possible to detect whether code is running in web or react-native? maybe by checking existence of some global variable? window?

from react-native-ultimate-config.

elliotdickison avatar elliotdickison commented on May 29, 2024

the very reason I created this project is to keep all platforms aligned. there are plenty of solutions which work good in pure js world but I want to be able to define variables in all platforms. having said that it seems natural to propagate values from ios/android to js.

The vision makes sense, I like it.

I wonder is it possible to have isomorphic implementation such that we don't have to generate separate d.ts file for overrides. Would the switch between the pure-js web module and the react-native module have to be automatic though?

I believe that building an automatic switch behinds the scenes would require dynamic imports (to avoid referencing react native modules in a web app)... not ideal. I think we could generate a separate build file specifically for the web though without duplicating types. Users could import the file via import config from "react-native-ultimate-config/web";, making it clear that they're getting a web-specific version. For universal react-native/react-native-web projects it is standard to use webpack to replace "react-native" imports with "react-native-web" imports, so we could write a bit o' documentation recommending the same thing to switch between "react-native-ultimate-config" and "react-native-ultimate-config/web".

These changes could be implemented separately from any modification to the js_override flag, but they would allow you to eventually drop the js_override flag in favor of import config from "react-native-ultimate-config/web"; which I think would be more in line with your vision of an "ultimate" config option that is the same everywhere in a react native app.

from react-native-ultimate-config.

maxkomarychev avatar maxkomarychev commented on May 29, 2024

Do you think we can do it relying on this feature of react-native and metro bundler https://reactnative.dev/docs/platform-specific-code ?

We could create a file index.js and index.native.js. In web projects you it would resolve to index.js free of all react-native imports. In RN projects it would resolve to index.native.js.

In such case we don't have to worry about dynamic and/or optional imports and simply have 2 files picked up by a bundler based on which bundler/env is used.

What do you think?

from react-native-ultimate-config.

maxkomarychev avatar maxkomarychev commented on May 29, 2024

published as part of 3.4.0

from react-native-ultimate-config.

maxkomarychev avatar maxkomarychev commented on May 29, 2024

thank you! <3

from react-native-ultimate-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.