Pull out `addMessage` from core.js into includes/message.ts
See original GitHub issueIs 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:
- Created a year ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
alright, got it.