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)
}
}
In many situations, a
Hook
orAction
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 ofAtlas
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: