ScriptApi separated from ScriptContext, preparation for modularisation

This commit is contained in:
azivner 2018-03-24 23:45:36 -04:00
parent c8e456cdb1
commit 001a5107dd
3 changed files with 23 additions and 23 deletions

View File

@ -1,25 +1,3 @@
function ScriptContext(startNote, allNotes) {
const modules = {};
return {
modules: modules,
notes: utils.toObject(allNotes, note => [note.noteId, note]),
apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note)]),
require: moduleNoteIds => {
return moduleName => {
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));
const note = candidates.find(c => c.title === moduleName);
if (!note) {
throw new Error("Could not find module note " + moduleName);
}
return modules[note.noteId].exports;
}
}
};
}
function ScriptApi(startNote, currentNote) {
const $pluginButtons = $("#plugin-buttons");

View File

@ -0,0 +1,21 @@
function ScriptContext(startNote, allNotes) {
const modules = {};
return {
modules: modules,
notes: utils.toObject(allNotes, note => [note.noteId, note]),
apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note)]),
require: moduleNoteIds => {
return moduleName => {
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));
const note = candidates.find(c => c.title === moduleName);
if (!note) {
throw new Error("Could not find module note " + moduleName);
}
return modules[note.noteId].exports;
}
}
};
}

View File

@ -555,7 +555,8 @@
<script src="/javascripts/link.js"></script>
<script src="/javascripts/sync.js"></script>
<script src="/javascripts/messaging.js"></script>
<script src="/javascripts/api.js"></script>
<script src="/javascripts/script_context.js"></script>
<script src="/javascripts/script_api.js"></script>
<script type="text/javascript">
// we hide container initally because otherwise it is rendered first without CSS and then flickers into