Files
Plugin-Example3/index.js

40 lines
1.0 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Example Plugin 3 - Async Operations & Storage
*/
let dataStore = {};
let intervalId = null;
export async function activate(context) {
context.log('Example Plugin 3 activated!');
// Register async data hook
context.registerHook('fetch-data', async (key) => {
context.log(`Fetching data for key: ${key}`);
await new Promise(resolve => setTimeout(resolve, 100)); // Simulate async operation
return dataStore[key] || null;
});
// Register data storage hook
context.registerHook('store-data', async (key, value) => {
context.log(`Storing data: ${key} = ${value}`);
dataStore[key] = value;
return true;
});
// Periodic status report
intervalId = setInterval(() => {
const keys = Object.keys(dataStore).length;
context.log(`Storage status: ${keys} entries`);
}, 30000);
}
export async function deactivate(context) {
if (intervalId) {
clearInterval(intervalId);
}
context.log('Example Plugin 3 deactivated!');
}
// Updated