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

479
Vistas
How to convert decorator @action to non-decorator action in MobX

I am removing decorators from my React Native app (too many issues with babel) and my actions are not working (the contained function does not run).

I'm translating class actions e.g.

class MyStore {
  //...

  @action 
  myAction(param) {
    //...
  }
}

To

class MyStore {
  //...

  myAction(param) {
    action("Perform action with param", (param) => {
      //...
    })
  }
}

What's the correct way to convert a class @action to the non-decorator form?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can define action as

class MyStore {
  //...

  myAction = action(param => {
    //...
  });
}

or use runInAction()

class MyStore {
  //...

  myAction(param) {
    runInAction(() => {
      //...
    })
  }
}
over 4 years ago · Santiago Trujillo Denunciar

0

What's the correct way to convert a class @action to the non-decorator form?

Decorators evaluate to function calls at runtime, so simply calling them manually would be the most straightforward thing to do. @action is a method decorator, and method decorators take the following arguments at runtime:

  1. The class prototype for instance methods (constructor function for static methods)
  2. The method name (property key)
  3. The property descriptor of the method

With that in mind, you can simply do:

class MyStore {
    myAction(param) {
        // ...
    }
}

// Apply the @action decorator manually:
action(MyStore.prototype, "myAction");

or:

action(MyStore.prototype, "myAction", Object.getOwnPropertyDescriptor(MyStore.prototype, "myAction"));

If you do this immediately after the class declaration, the result should be completely identical to that by using decorators, without having to use the decorator syntax.

over 4 years ago · Santiago Trujillo Denunciar
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