Atom Operations at Frontend

EggBornJS injects an object $api into the frontend component. In the frontend component, you can access the backend API route through this.$api to perform atom operations

Atom Operations at Backend

the module a-base injects object atom into ctx through middleware mechanism. Atom operations can be performed through ctx.meta.atom

create

Frontend

this.$api.post('/a/base/atom/create', {
  atomClass: {
    id,
    module,
    atomClassName,
  },
}).then(key => {
  console.log(key);
});

Return Result

Name Description
key Atom Key:{ atomId, itemId }

Parameters

Name Description
atomClass.id AtomClass’s Id
atomClass.module AtomClass Module Name
atomClass.atomClassName AtomClass Name

If atomClass.Id is specified, then atomClass.module and atomClass.atomClassName' need not be specified

Otherwise, if atomClass.id is not specified, then atomClass.module and atomClass.atomClassName must be specified

Backend

const user = this.ctx.user.op;
const key = await this.ctx.meta.atom.create({
  atomClass: {
    id,
    module,
    atomClassName,
  },
  user,
});
Name Description
atomClass
user the current user

write

Frontend

this.$api.post('/a/base/atom/write', {
  key: { atomId, itemId },
  item,
}).then(() => {
});

Parameters

Name Description
key Atom Key
item atom data

Backend

const user = this.ctx.user.op;
await this.ctx.meta.atom.write({
  key: { atomId, itemId },
  item,
  user,
});
Name Description
key Atom Key
item atom data
user the current user

delete

Frontend

this.$api.post('/a/base/atom/delete', {
  key: { atomId, itemId },
}).then(() => {
});

Backend

const user = this.ctx.user.op;
await this.ctx.meta.atom.delete({
  key: { atomId, itemId },
  user,
});

enable

Submission of atoms from the draft state to the normal state

Frontend

this.$api.post('/a/base/atom/enable', {
  key: { atomId, itemId },
}).then(() => {
});

Backend

const user = this.ctx.user.op;
await this.ctx.meta.atom.enable({
  key: { atomId, itemId },
  atom: { atomEnabled: 1 },
  user,
});

action

Perform the custom actions

Frontend

this.$api.post('/a/base/atom/action', {
  action: 101,
  key: { atomId, itemId },
}).then(() => {
});
Name Description
action action’s code

Backend

const user = this.ctx.user.op;
await this.ctx.meta.atom.action({
  action: 101,
  key: { atomId, itemId },
  user,
});

flag

Change the Atom Flag

Frontend

this.$api.post('/a/base/atom/flag', {
  key: { atomId, itemId },
  atom: { atomFlag },
}).then(() => {
});

Backend

const user = this.ctx.user.op;
await this.ctx.meta.atom.flag({
  key: { atomId, itemId },
  atom: { atomFlag },
  user,
});

flow

Change the Atom Flow

Frontend

this.$api.post('/a/base/atom/flow', {
  key: { atomId, itemId },
  atom: { atomFlow },
}).then(() => {
});

Backend

const user = this.ctx.user.op;
await this.ctx.meta.atom.flow({
  key: { atomId, itemId },
  atom: { atomFlow },
  user,
});