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.
This commit is contained in:
Richard Hansen 2021-11-28 19:27:46 -05:00
parent f7d4abdabe
commit 885ff3bcde
3 changed files with 8 additions and 7 deletions

View file

@ -175,14 +175,15 @@ Things in context:
This hook gets called when a new pad was created. This hook gets called when a new pad was created.
## padLoad ## `padLoad`
Called from: src/node/db/Pad.js
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 ## padUpdate
Called from: src/node/db/Pad.js Called from: src/node/db/Pad.js

View file

@ -366,8 +366,6 @@ Pad.prototype.init = async function (text) {
await this.appendRevision(firstChangeset, ''); await this.appendRevision(firstChangeset, '');
} }
hooks.callAll('padLoad', {pad: this});
}; };
Pad.prototype.copy = async function (destinationID, force) { Pad.prototype.copy = async function (destinationID, force) {

View file

@ -22,6 +22,7 @@
const CustomError = require('../utils/customError'); const CustomError = require('../utils/customError');
const Pad = require('../db/Pad').Pad; const Pad = require('../db/Pad').Pad;
const db = require('./DB'); const db = require('./DB');
const hooks = require('../../static/js/pluginfw/hooks');
/** /**
* A cache of all loaded Pads. * A cache of all loaded Pads.
@ -141,6 +142,7 @@ exports.getPad = async (id, text) => {
// initialize the pad // initialize the pad
await pad.init(text); await pad.init(text);
hooks.callAll('padLoad', {pad});
globalPads.set(id, pad); globalPads.set(id, pad);
padList.addPad(id); padList.addPad(id);