-
Notifications
You must be signed in to change notification settings - Fork 584
[docs] Document the JS Deprecation utilities and process #1562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewnicols
wants to merge
1
commit into
moodle:main
Choose a base branch
from
andrewnicols:MDL-87867
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| --- | ||
| title: Deprecation of JavaScript | ||
| tags: | ||
| - deprecation | ||
| --- | ||
|
|
||
| The deprecation of JavaScript follows the same general principle as the deprecation of other Moodle code. That is: | ||
|
|
||
| - Deprecations should only be on the `main` branch, not on stables. Exceptions to this may be made in certain conditions, including: | ||
| - for some external service integrations | ||
| - where a feature is discovered to have been broken irreparably | ||
| - to address security issues | ||
| - Deprecations apply to all public APIs, classes, and files. | ||
| - All deprecations should be noted with an [upgrade note](/general/development/upgradenotes). | ||
| - Deprecations are split into three stages: | ||
| 1. Initial deprecation | ||
| 2. Final deprecation | ||
| 3. Removal | ||
| - All deprecations should emit debugging notices where possible | ||
|
|
||
| ## JavaScript specifics {/* #JavaScript-specifics */} | ||
|
|
||
| <Since version="5.2" issueNumber="MDL-87867" /> | ||
|
|
||
| From Moodle 5.2 a new deprecation utility is included in Moodle core for JavaScript. That can be found in the `core/deprecated` AMD module and is intended to function in a similar way to its PHP Attribute equivalent. | ||
|
|
||
| ### Usage {/* #usage */} | ||
|
|
||
| The `core/deprecated` module exports a single, default, function which can be used to emit appropriate deprecation information when called. | ||
|
|
||
| This may be included in places such as: | ||
|
|
||
| - the body of the file, not in any method, so that the use of the file emits the deprecation notices; and | ||
| - within a method, so that when a method is called the deprecation notice is emitted. | ||
|
|
||
| The basic usage of the API requires that a description of the thing being deprecated is provided. Other arguments are optional, but at least one of the following must be provided: | ||
|
|
||
| - the reason for deprecation; | ||
| - the replacement to use; or | ||
| - the MDL in which the item was deprecated. | ||
|
|
||
| ```javascript title="Basic usage" | ||
| import emitDeprecation from 'core/deprecated'; | ||
|
|
||
| export const myFunction = (the, args) => { | ||
| emitDeprecation('myFunction', { | ||
| replacement: 'myNewFunction', | ||
| since: '5.2', | ||
| mdl: 'MDL-12345', | ||
| }); | ||
|
|
||
| const modified = args.slice(0, 1); | ||
| args = args.slice(1); | ||
|
|
||
| // Call myNewFunction. | ||
| return myNewFunction(the, modified, args); | ||
| } | ||
| ``` | ||
|
|
||
| When this method is called the following actions will happen: | ||
|
|
||
| - a notice will be printed to the browser console; and | ||
| - a modal will be displayed. | ||
|
|
||
| This deprecation will cause failures when running Behat if any code path makes use of the functionality. | ||
|
|
||
| #### Silent deprecation {/* #silent-deprecation */} | ||
|
|
||
| In some cases it is necessary to deprecate a feature silently, emitting to the console but not displaying any modal. This may happen for deprecation of widely used features over a longer period where the initial deprecation is expected to take a long time. | ||
|
|
||
| To do this, you can set the `emit: false` property on the deprecation call: | ||
|
|
||
| ```javascript title="Emitting in the Console only" | ||
| import emitDeprecation from 'core/deprecated'; | ||
|
|
||
| export const myFunction = (the, args) => { | ||
| emitDeprecation('myFunction', { | ||
| replacement: 'myNewFunction', | ||
| since: '5.2', | ||
| mdl: 'MDL-12345', | ||
| emit: false, | ||
| }); | ||
|
|
||
| const modified = args.slice(0, 1); | ||
| args = args.slice(1); | ||
|
|
||
| // Call myNewFunction. | ||
| return myNewFunction(the, modified, args); | ||
| } | ||
andrewnicols marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| #### Final deprecation {/* #final-deprecation */} | ||
|
|
||
| After the initial deprecation period, deprecations typically then become 'final'. This means that instead of a warning being issued and a backwards-compatible call being made, an Error is shown. | ||
|
|
||
| In some cases deprecations may also be marked as final because there is no alternative. | ||
|
|
||
| To mark a deprecation as final, you can set the `final: true` property on the deprecation call: | ||
|
|
||
| ```javascript title="Basic usage" | ||
| import emitDeprecation from 'core/deprecated'; | ||
|
|
||
| export const myFunction = (the, args) => { | ||
| emitDeprecation('myFunction', { | ||
| replacement: 'myNewFunction', | ||
| since: '5.2', | ||
| mdl: 'MDL-12345', | ||
| final: true, | ||
| }); | ||
|
|
||
| const modified = args.slice(0, 1); | ||
| args = args.slice(1); | ||
|
|
||
| // Call myNewFunction. | ||
| return myNewFunction(the, modified, args); | ||
| } | ||
andrewnicols marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### Tips and tricks {/* #tips-and-tricks */} | ||
|
|
||
| #### Hiding deprecations {/* #hiding-deprecations */} | ||
|
|
||
| If you wish to stop this deprecation from displaying and from causing Behat failures, you can set the following in your `config.php`: | ||
|
|
||
| ```php title="Ignoring the deprecation of 'myFunction'" | ||
| $CFG->jsdeprecationignorelist = [ | ||
| 'myFunction', | ||
| ]; | ||
| ``` | ||
|
|
||
| The name in this list should match the first argument to the `emitDeprecation` method. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| title: Deprecation of JavaScript | ||
| tags: | ||
| - deprecation | ||
| --- | ||
|
|
||
| The deprecation of JavaScript follows the same general principle as the deprecation of other Moodle code. That is: | ||
|
|
||
| - Deprecations should only be on the `main` branch, not on stables. Exceptions to this may be made in certain conditions, including: | ||
| - for some external service integrations | ||
| - where a feature is discovered to have been broken irreparably | ||
| - to address security issues | ||
| - Deprecations apply to all public APIs, classes, and files. | ||
| - All deprecations should be noted with an [upgrade note](../../upgradenotes.md). | ||
| - Deprecations are split into three stages: | ||
| 1. Initial deprecation | ||
| 2. Final deprecation | ||
| 3. Removal | ||
| - All deprecations should emit debugging notices where possible | ||
|
|
||
| ## JavaScript specifics {/* #JavaScript-specifics */} | ||
|
|
||
| <Since version="5.2" issueNumber="MDL-87867" /> | ||
|
|
||
| From Moodle 5.2 a new deprecation utility is included in Moodle core for JavaScript. That can be found in the `core/deprecated` AMD module and is intended to function in a similar way to its PHP Attribute equivalent. | ||
|
|
||
| See the [JavaScript Guide to deprecation](/docs/guides/javascript/deprecation) for more information on how to use this feature. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.