question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pull out `addMessage` from core.js into includes/message.ts

See original GitHub issue

Is your proposal related to a problem?

addMessage should move from core.js to a new file client/src/includes/messages.ts

Wagtail’s JavaScript core.js is quite large and many items can be pulled out to shared utils or includes to help make the code more maintainable and supported with base unit tests.

Pulling some basic functions out lets us put these into TypeScript (type safety) but also document and unit test them better.

Describe the solution you’d like

The function addMessage should be moved from https://github.com/wagtail/wagtail/blob/aaea8710c21ba4d5368d3825781bc54e1869c561/client/src/entrypoints/admin/core.js#L4-L14

To a new file client/src/includes/messages.ts (note: TypeScript ts not JavaScript js)

From there it can be imported and set to the same global (window.addMessage) as per current state.

Requirements

  • Move the function to the the new TypeScript file and set up correct types - https://www.typescriptlang.org/
  • Add a JSDOC description to the function
  • Add a basic set unit test (just one is fine) for this function in a new client/src/includes/messages.test.js file using Jest - look at client/src/includes/breadcrumbs.test.js for an example of mocking some HTML to then trigger some behaviour on that HTML
  • Ensure the util is imported in core.js correctly so that window.addMessage and any other usage within that function still acts the same way.

Additional context

  • This has been created as part of the Outreachy program to help new contributors that are interested in the Stimulus project.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lb-commented, Nov 22, 2022

@salty-ivy I think it may be best you look at some of those other ones I pinged you on yesterday.

Let’s let Ivy pursue this, it’s not a critical improvement and it’s very possible we will look at this code differently in the coming weeks with the Stimulus RFC 78 work.

0reactions
salty-ivycommented, Nov 23, 2022

alright, got it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can the polyfill.ts file be deleted? - Stack Overflow
Try to avoid deleting this file because polyfill.ts contains zone.js polyfill. Your app may produce errors when running on older browsers. You ...
Read more >
core-js - npm
Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2023: promises, symbols, collections, iterators, typed arrays, ...
Read more >
Error.prototype.message - JavaScript - MDN Web Docs
This property contains a brief description of the error if one is available or has been set. The message property combined with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found