buddy

node MVC discord bot
Log | Files | Refs | README

Base.js (720B)


      1 'use strict';
      2 
      3 const Util = require('../util/Util');
      4 
      5 /**
      6  * Represents a data model that is identifiable by a Snowflake (i.e. Discord API data models).
      7  */
      8 class Base {
      9   constructor(client) {
     10     /**
     11      * The client that instantiated this
     12      * @name Base#client
     13      * @type {Client}
     14      * @readonly
     15      */
     16     Object.defineProperty(this, 'client', { value: client });
     17   }
     18 
     19   _clone() {
     20     return Object.assign(Object.create(this), this);
     21   }
     22 
     23   _patch(data) {
     24     return data;
     25   }
     26 
     27   _update(data) {
     28     const clone = this._clone();
     29     this._patch(data);
     30     return clone;
     31   }
     32 
     33   toJSON(...props) {
     34     return Util.flatten(this, ...props);
     35   }
     36 
     37   valueOf() {
     38     return this.id;
     39   }
     40 }
     41 
     42 module.exports = Base;