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

Support stateless components #53

@robertrossmann

Description

@robertrossmann

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)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions