From 4b3f71b25e79246c89d6d1cf2b33386820bb61d5 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Fri, 13 Dec 2024 10:20:31 -0500 Subject: [PATCH] dev: migrate listenerutil, remove duplicate --- src/backend/src/filesystem/FSNodeContext.js | 6 +- src/backend/src/util/listenerutil.js | 80 --------------------- src/putility/index.js | 6 +- src/putility/src/libs/listener.js | 1 + 4 files changed, 7 insertions(+), 86 deletions(-) delete mode 100644 src/backend/src/util/listenerutil.js diff --git a/src/backend/src/filesystem/FSNodeContext.js b/src/backend/src/filesystem/FSNodeContext.js index d7387348..e86b2a90 100644 --- a/src/backend/src/filesystem/FSNodeContext.js +++ b/src/backend/src/filesystem/FSNodeContext.js @@ -18,11 +18,13 @@ */ const { get_user, get_dir_size, id2path, id2uuid, is_empty, is_shared_with_anyone, suggest_app_for_fsentry, get_app } = require("../helpers"); +const putility = require('@heyputer/putility'); +const { MultiDetachable } = putility.libs.listener; +const { TDetachable } = putility.traits; const config = require("../config"); const _path = require('path'); const { NodeInternalIDSelector, NodeChildSelector, NodeUIDSelector, RootNodeSelector, NodePathSelector } = require("./node/selectors"); const { Context } = require("../util/context"); -const { MultiDetachable } = require("../util/listenerutil"); const { NodeRawEntrySelector } = require("./node/selectors"); const { DB_READ } = require("../services/database/consts"); const { UserActorType } = require("../services/auth/Actor"); @@ -287,7 +289,7 @@ module.exports = class FSNodeContext { const detachables = new MultiDetachable(); const callback = (resolver) => { - detachables.detach(); + detachables.as(TDetachable).detach(); rslv(); } diff --git a/src/backend/src/util/listenerutil.js b/src/backend/src/util/listenerutil.js deleted file mode 100644 index f6b3c8ee..00000000 --- a/src/backend/src/util/listenerutil.js +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2024 Puter Technologies Inc. - * - * This file is part of Puter. - * - * Puter is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -// DEPRECATED: use putility.libs.listener instead - -class MultiDetachable { - constructor() { - this.delegates = []; - this.detached_ = false; - } - - add (delegate) { - if ( this.detached_ ) { - delegate.detach(); - return; - } - - this.delegates.push(delegate); - } - - detach () { - this.detached_ = true; - for ( const delegate of this.delegates ) { - delegate.detach(); - } - } -} - -class AlsoDetachable { - constructor () { - this.also = () => {}; - } - - also (also) { - this.also = also; - return this; - } - - detach () { - this.detach_(); - this.also(); - } -} - -// TODO: this doesn't work, but I don't know why yet. -class RemoveFromArrayDetachable extends AlsoDetachable { - constructor (array, element) { - super(); - this.array = array; - this.element = element; - } - - detach_ () { - const index = this.array.indexOf(this.element); - if ( index !== -1 ) { - this.array.splice(index, 1); - } - } -} - -module.exports = { - MultiDetachable, - RemoveFromArrayDetachable, -}; diff --git a/src/putility/index.js b/src/putility/index.js index 4390bd39..164c7d94 100644 --- a/src/putility/index.js +++ b/src/putility/index.js @@ -19,7 +19,7 @@ const { AdvancedBase } = require('./src/AdvancedBase'); const { Service } = require('./src/concepts/Service'); const { ServiceManager } = require('./src/system/ServiceManager'); -const { TTopics } = require('./src/traits/traits'); +const traits = require('./src/traits/traits'); module.exports = { AdvancedBase, @@ -38,7 +38,5 @@ module.exports = { concepts: { Service, }, - traits: { - TTopics, - }, + traits, }; diff --git a/src/putility/src/libs/listener.js b/src/putility/src/libs/listener.js index 1d54b93d..1255fb75 100644 --- a/src/putility/src/libs/listener.js +++ b/src/putility/src/libs/listener.js @@ -29,6 +29,7 @@ class MultiDetachable extends FeatureBase { ]; constructor() { + super(); this.delegates = []; this.detached_ = false; }