From 885ff3bcde9e00ca6f278ca0584a1a2d58a79d86 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 28 Nov 2021 19:27:46 -0500 Subject: [PATCH] Pad: Move `padLoad` hook invocation to `PadManager.js` This puts global state change logic with the rest of the global state management logic. This also makes it possible to create temporary Pad objects without triggering plugin actions. --- doc/api/hooks_server-side.md | 11 ++++++----- src/node/db/Pad.js | 2 -- src/node/db/PadManager.js | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index 5e8832fd4..50dfff0db 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -175,14 +175,15 @@ Things in context: This hook gets called when a new pad was created. -## padLoad -Called from: src/node/db/Pad.js +## `padLoad` -Things in context: +Called from: `src/node/db/PadManager.js` -1. pad - the pad instance +Called when a pad is loaded, including after new pad creation. -This hook gets called when a pad was loaded. If a new pad was created and loaded this event will be emitted too. +Context properties: + +* `pad`: The Pad object. ## padUpdate Called from: src/node/db/Pad.js diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 1307bcb89..9e1ef0399 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -366,8 +366,6 @@ Pad.prototype.init = async function (text) { await this.appendRevision(firstChangeset, ''); } - - hooks.callAll('padLoad', {pad: this}); }; Pad.prototype.copy = async function (destinationID, force) { diff --git a/src/node/db/PadManager.js b/src/node/db/PadManager.js index 58434c8cd..40b27383e 100644 --- a/src/node/db/PadManager.js +++ b/src/node/db/PadManager.js @@ -22,6 +22,7 @@ const CustomError = require('../utils/customError'); const Pad = require('../db/Pad').Pad; const db = require('./DB'); +const hooks = require('../../static/js/pluginfw/hooks'); /** * A cache of all loaded Pads. @@ -141,6 +142,7 @@ exports.getPad = async (id, text) => { // initialize the pad await pad.init(text); + hooks.callAll('padLoad', {pad}); globalPads.set(id, pad); padList.addPad(id);