dev: migrate listenerutil, remove duplicate

This commit is contained in:
KernelDeimos
2024-12-13 10:20:31 -05:00
parent c792f4a345
commit 4b3f71b25e
4 changed files with 7 additions and 86 deletions

View File

@@ -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();
}

View File

@@ -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 <https://www.gnu.org/licenses/>.
*/
// 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,
};

View File

@@ -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,
};

View File

@@ -29,6 +29,7 @@ class MultiDetachable extends FeatureBase {
];
constructor() {
super();
this.delegates = [];
this.detached_ = false;
}