[RANDOM] Circular class recurrence
SudoJunior
Posted on December 7, 2018
no actual content just code
// file: ./src/classes/User/index.js
const { r } = require('rethinkdb-ts');
/**
* @typedef {import('discord.js').User} DiscordUser
*/
// [internal]
const Admin = require('./Admin.js');
class User {
/**
* @param {DiscordUser} user
*/
constructor(user) {
this._client = user.client
this.user = user;
}
get query() {
return r.table('users').get(this.user.id);
}
get r() {
return r;
}
get admin() {
return new Admin(this.user);
}
}
module.exports = User;
// file: ./src/classes/User/Admin.js
/**
* @typedef {import('discord.js').User} DiscordUser
*/
class Admin {
/**
* @param {DiscordUser} user
*/
constructor(user) {
this._client = user.client;
this.user = user;
}
get _() {
let Seed = require('./');
return new Seed(this.user);
}
}
module.exports = Admin;
efficient? f*ck no
cool? yea, sure
what does it do?
(in short) it is class file recurrence, where the Admin class is getting the 'seed' file to return to its intended state.
(ref to discord.js) the user class instance is passed through both constructors therefore allowing for deeper recurrence.
this is not singleton programming, if it was i would have passed the class instance through... but i couldn't figure that one out at the time.
Updated 2019/03/21 13:13 GMT London
Replaced module support for rethinkdb-ts for better type resolving.
💖 💪 🙅 🚩
SudoJunior
Posted on December 7, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.