hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
901 stars 57 forks source link

replaceEnv can now take function as value. #28

Closed frnk94 closed 8 years ago

frnk94 commented 9 years ago

I use envify to send my configs and some of them are functions. The JSON.stringify(value) return undefined when value is a function.

yoshuawuyts commented 9 years ago

I'm -1 on this patch; passing functions around as values doesn't seem like a good approach. Consider passing the results of those functions around instead.

frnk94 commented 9 years ago

This functions is uses by my frontend (React components) so i can't just pass the values of the function because it differ according to its state. This function also need to be calculated backend from our ORM

yoshuawuyts commented 9 years ago

So if I understand you correctly, you want to append functions to process.env to make them available globally and consume them in your components?

yoshuawuyts commented 9 years ago

Is there a reason you need to build the functions on the server and can't just pass the data to the client?

frnk94 commented 8 years ago

This is why I need to pass a function I want to have constancy in my code base. This function is used by my backend & frontend. the value pass to the function depend on the state of my application.

exemple:

React.createClass({
    getInitialState() {
        return {
           number: 0,
       }
   },
   calculatePrice() {
        process.env.getPrice(this.state.number);
    },
    render() {
        return (
            <div>{this.calculatePrice()}</div>
       );
   },
});
yoshuawuyts commented 8 years ago

I feel this complicates things too much and there's very little interest from others. While I appreciate the effort you've put into this I'd rather be forward and close this PR than leave it open and unanswered. Thanks a bunch, but this is not going to land as of now.