... this.me Docs me.js

Source

me.js

//src/me.js
import { getMe } from './modules/identity.js';
import { be, getAttributes } from './modules/attributes.js';
import { addRelationship, getRelationships } from './modules/relationships.js';
import { react, getReactions } from './modules/reactions.js';
import { addProperty, getProperties } from './modules/properties.js';

/**
 * @class Me
 * @description The core identity class for managing attributes, relationships, reactions, and properties.
 * 
 * This class represents the "me" instance, which is the core identity object. You only need to pass 
 * a username when creating a new instance of `Me`, and this username will automatically become the 
 * identity of the `me` instance.
 *
 * Once an instance is created, you can interact with it by managing attributes, relationships, 
 * reactions, and properties using the methods provided.
 *
 *  @example
 * // Creating a new Me instance
 * let me = new Me("suiGn");
 */
class Me {
  constructor({ username }) {
    this.me = { username };
    this.attributes = {};
    this.relationships = [];
    this.reactions = [];
    this.properties = [];
  }

  getMe() {
    return getMe(this.me);
  }

  be(key, value) {
    be(this.attributes, key, value);
  }
 
  getAttributes() {
    return getAttributes(this.attributes);
  }

  // Relationships methods
  addRelationship(relationship) {
    addRelationship(this.relationships, relationship);
  }

  getRelationships() {
    return getRelationships(this.relationships);
  }

  // Reactions methods
  react(type, target, content = null) {
    react(this.reactions, type, target, content);
  }

  getReactions() {
    return getReactions(this.reactions);
  }

  // Properties methods
  addProperty(property) {
    addProperty(this.properties, property);
  }

  getProperties() {
    return getProperties(this.properties);
  }
}

export default Me;

By neurons.me