Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Support stateless components #53

Open
robertrossmann opened this issue Jun 26, 2018 · 1 comment
Open

Support stateless components #53

robertrossmann opened this issue Jun 26, 2018 · 1 comment

Comments

@robertrossmann
Copy link
Member

In many situations, a Hook or Action could be completely stateless (just a bunch of functions), and so the requirement to write such components as classes becomes unnecessary and even counter-intuitive.

If a component is to be shared between multiple possible instances of Atlas in the same process then the component must be written as a class, otherwise it's not clear how to get hold of the correct instance of Atlas class which should be used to handle the request or where to get the reference to other components.

For all other use cases (single-Atlas-instance apps, 95% of normal use cases), one can do the following:

// path to project root
import atlas from '..'
// example path to a place where other stateless components exist
import { notifier } from '.'

// This is a stateless action component
export default {
  async createAccount(info) {
    // Example how to access other components from this component
    const user = await atlas.services.database.users.insert(info)
    // Example how to use other stateless components
    await notifier.sendEmail('welcome-message', user.email, user)
  }
}
@robertrossmann
Copy link
Member Author

@thunderball1 Is the code example above somewhat similar to what you are after?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant