Skip to content

Conversation

mlevison
Copy link

This is the start of the refactoring I proposed in discord.

I created a NotesFactory - since some of the examples are borrowed from helpers/tests/paragraph.test.js - it would easy to refactor.

I added tasks.js to helpers and I intend to migrate the other task related functions there as I find them. I.E. from sorting, getAllTasksByType()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlevison This is a great start. Thanks! A starting observation:

  • For generalized use, the term "note" is misleading here, because these objects you created are not notes, they are objects with paragraphs arrays. In your tests, you are just accessing that one attribute, which makes sense. However the term "note" is an important distinction because if I wanted to construct a test, I would expect a note to have a title, type, filename, frontmatterAttributes, etc. This is why I was suggesting you use JEST helpers to give you a quick/easy way to create basic note attributes in JSON form.
  • Also, defining them all in a single file may get unwieldy if we add lots and lots of them over time. you may want to search the code for the string "const factory = async" to see how factory files are loaded dynamically in Templating by Mike. this way, each test file is actually its own file and does not have to be concatenated in a never-ending single file. That said, I don't like that the Templating factory loader code is import code is repeated. should definitely be a shared function.
    There are a always a lot of ways to deal with these two things. Look forward to hearing your thoughts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And on a different 'note' (ha ha), I would even at this early stage suggest adding a richer set of content. I.e. note links, dates, emojis, URLs, Markdown links, non-Roman characters. Each of these has caused issues in the past.

@mlevison
Copy link
Author

Happy to make improvements.

  • I will tweak the note stuff. Where would I find an example of: "This is why I was suggesting you use JEST helpers to give you a quick/easy way to create basic note attributes in JSON form." - since I'm new(ish) to JavaScript I need an example.
  • Single file - unweildy true. However, my approach is to refactor when it gets big, that is when I will know what the parts are.

@dwertheimer
Copy link
Collaborator

@mlevison

build JestHelpers:

Screen Cap 2025-07-22 at 10 48 28@2x

That will then allow you to run a command:
Screen Cap 2025-07-22 at 10 50 28@2x

Which will give you the JSON for the existing note in the Editor:
Screen Cap 2025-07-22 at 10 51 03@2x

@dwertheimer
Copy link
Collaborator

@mlevison I'm totally with you on refactoring once a file gets large, but please do have a look at the factories loading in the np.Templating plugin per my previous comment. I think it would be better architecturally to have each note JSON as its own file and then dynamically load them by name when needed rather than having all the notes as a const in one file.

@dwertheimer
Copy link
Collaborator

@mlevison I just realized that frontmatter attributes was not yet included in the output from JestHelpers so I am pushing that to main. please pull the latest from main and update your branch with this new version.

Copy link
Collaborator

@jgclark jgclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added one comment, about 'tricky' content, but otherwise I'm OK with it so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants