Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
How to abstract environmental JS class implementations

I have an abstraction of an adapter. Through an environmeht variable I control which implementation is used. I am not satisfied with this approach, since the mock variant is imported in production code. I would like to have something like in Symfony, where implementation of abstractions can be defined in environmental service configurations.

Currently I have following abstraction:

import HttpERPAdapter from "./HttpERPAdapter";
import MockERPAdapter from "./MockERPAdapter"; // todo, find an abstraction solution to not deploy this in production
import httpClient from "common/HttpClient";

const create = () => {
    if (process.env.REACT_APP_ERP_API_URL === 'mock') {
        return new MockERPAdapter();
    }
    return new HttpERPAdapter(httpClient);
}

const erpAdapter = create();
export default erpAdapter;
  • The mock variant: Mainly used when developing GUI when I have not to rely on real api data, for faster development.
  • The productive variant: For for developing with real api data, and for the productive build

I am sure that a compilation in a production build will contain the mock class, this is also what I want to prevent.
In general I want that the productive code knows nothing about mocks/fake-services.

Any ideas on how to separate the mock implementation from the productive code?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda