discourse/app/assets/javascripts
Sérgio Saquetim 9668592aab
DEV: Introduce a value transformer front-end plugin API (#27090)
This commit introduces the `valueTransformer`API to safely override values defined in Discourse.

Two new plugin APIs are introduced:

- `addValueTransformerName` which allows plugins and theme-components to add a new valid transformer name if they want to provide overridable values;
- `registerValueTransformer` to register a transformer to override values.

It also introduces the function `applyValueTransformer` which can be imported from `discourse/lib/transformer`. This function marks the desired value as overridable and applies the transformer logic.

How does it work?

## Marking a value as overridable:
 
To mark a value as overridable, in Discourse core, first the transformer name must be added to `app/assets/javascripts/discourse/app/lib/transformer/registry.js`. For plugins and theme-components, use the plugin API `addValueTransformerName` instead.

Then, in your component or class, use the function `applyValueTransformer` to mark the value as overridable and handle the logic:

- example:

```js
export default class HomeLogo extends Component {
  @service session;
  @service site;
  ...
  get href() {
    return applyValueTransformer("home-logo-href", getURL("/"));
  }	
```

## Overriding a value in plugins or themes

To override a value in plugins, themes, or TCs use the plugin API `registerValueTransformer`:

- Example:

```js
withPluginApi("1.34.0", (api) => {
  api.registerValueTransformer("example-transformer", ({ value }) => {
    return "new-value";
  });
});
```
2024-06-12 15:21:52 -03:00
..
admin Build(deps): Bump ember-resolver from 12.0.0 to 12.0.1 (#27432) 2024-06-12 00:49:16 +02:00
custom-proxy Build(deps-dev): Bump glob from 10.3.16 to 10.4.1 (#27186) 2024-05-27 11:41:43 +02:00
deprecation-silencer DEV: Silence whitespace-eating-comment warnings (#27129) 2024-05-22 16:21:51 +02:00
dialog-holder Build(deps-dev): Bump webpack from 5.91.0 to 5.92.0 (#27429) 2024-06-12 00:46:44 +02:00
discourse DEV: Introduce a value transformer front-end plugin API (#27090) 2024-06-12 15:21:52 -03:00
discourse-common Build(deps): Bump ember-resolver from 12.0.0 to 12.0.1 (#27432) 2024-06-12 00:49:16 +02:00
discourse-hbr DEV: Convert discourse-hbr to a regular package (#26562) 2024-04-08 20:00:34 +01:00
discourse-i18n Build(deps): Bump @embroider/addon-shim in the embroider group (#27142) 2024-05-23 00:32:09 +02:00
discourse-markdown-it PERF: Avoid excessive object creations in watched words (#27354) 2024-06-10 14:44:31 +02:00
discourse-plugins Build(deps-dev): Bump webpack from 5.91.0 to 5.92.0 (#27429) 2024-06-12 00:46:44 +02:00
discourse-widget-hbs Build(deps): Bump ember-resolver from 12.0.0 to 12.0.1 (#27432) 2024-06-12 00:49:16 +02:00
docs
ember-addons
ember-cli-progress-ci PERF: Improve production JS build in low-memory environments (#26849) 2024-05-02 11:43:59 +01:00
ember-production-deprecations DEV: Drop unused shims for Ember 3 deprecations (#26563) 2024-04-09 09:22:37 +01:00
float-kit Build(deps): Bump ember-resolver from 12.0.0 to 12.0.1 (#27432) 2024-06-12 00:49:16 +02:00
locales FEATURE: Add Uyghur language (#27183) 2024-05-27 09:58:18 +02:00
pretty-text Build(deps): Bump ember-resolver from 12.0.0 to 12.0.1 (#27432) 2024-06-12 00:49:16 +02:00
select-kit Build(deps): Bump ember-resolver from 12.0.0 to 12.0.1 (#27432) 2024-06-12 00:49:16 +02:00
theme-transpiler DEV: @babel/plugin-proposal-decorators -> decorator-transforms (#27260) 2024-06-10 15:51:48 +01:00
truth-helpers Build(deps): Bump ember-auto-import from 2.7.2 to 2.7.3 (#27235) 2024-05-29 08:14:00 +08:00
.npmrc
handlebars-shim.js
polyfills.js
run-patch-package
service-worker.js.erb DEV: Drop workbox dependency (#26735) 2024-04-24 10:19:12 +01:00