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

Decide how to use namespaces in the store #138

@luisherranz

Description

@luisherranz

I have been talking to @SantosGuillamot and we thought that just using the namespace after state, actions, effects, etc, should be enough to avoid collisions.

The namespace should be the same as the one used in the blocks, defined in the documentation as:

The name for a block is a unique string that identifies a block. Names have to be structured as namespace/block-name, where namespace is the name of your plugin or theme.

Within the namespace, developers can do whatever they want. If they define values in the root, they will be as global values to their namespace, and if they have several blocks with properties that may conflict, they can also use the names of each block to further subdivide the state.

The definition of a single store would look like this:

store({
  state: {
    myPlugin: {
      // Inside state.myPlugin, the creator of my-plugin can organize whatever they want.
      value: 123,
      someBlock: {
        value: 456,
      },
      otherBlock: {
        value: 789,
      },
    },
  },
  actions: {
    myPlugin: {
      // Inside actions.myPlugin, the creator of my-plugin can organize whatever they want.
    }
  }
});

And a complete store would look like this:

{
  state: {
    woo: {
      value: 123,
      cart: {
        // ...
      },
      filters: {
        // ...
      },
    },
    myPlugin: {
      value: 123,
      someBlock: {
        value: 456,
      },
      otherBlock: {
        value: 789,
      },
    },
  },
  actions: {
    woo: {
      // ...
    },
    myPlugin: {
      // ...
    },
  },
};

Thoughts?

cc: @WordPress/frontend-dx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions