mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 19:03:13 +08:00
fb9948c79c
Browser capabilities are inherently unconnected to the lifecycle of our app. Making them formally available outside of the service means that they can safely be used in non-app-linked functions without needing risky hacks like `helperContext()` or `discourse-common/lib/get-owner`. One example of where the old hacks were problematic is the `translateModKey()` utility function. This is called in the root of the `discourse/components/modal/keyboard-shortcuts-help` es6 module. If anything (e.g. a theme/plugin) caused that es6 module to be `require()`d before the application was booted, a fatal error would occur. Following this commit, `translateModKey()` can safely import and access `capabilities` without needing to worry about the app lifecycle. The only potential downside to this approach is that the capabilities data now persists across tests. If any tests need to 'stub' capabilities, they will need to revert their changes at the end of the test (e.g. by using Sinon to stub a property). This commit also updates some legacy references from `capabilities:main` to `service:capabilities`. |
||
---|---|---|
.. | ||
assets | ||
controllers | ||
helpers | ||
jobs | ||
mailers | ||
models | ||
serializers | ||
services | ||
views |