# Aggiungere dati 'opts' extra all'evento "DiscourseEvent.on(:post\_created)" da JavaScript?

**URL:** <https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889>\
**Category:** Development\
**Created:** [9 Aprile 2018, 4:05pm UTC](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889 "2018-04-09T16:05:46Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Vespura](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vespura/32/206564_2.png) [@Vespura](https://meta.discourse.org/u/Vespura)\
**Post date:** [11 Aprile 2018, 10:00pm UTC](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889/7 "2018-04-11T22:00:55Z")

</div>

Thanks for the reply. I currently have this in my initializer:

```js
var hide = true; // this gets toggled true/false whenever the button is pressed.

function initializeHideToggle(api) {
  api.includePostAttributes('hide_devs');

  api.modifyClass('model:composer', {
    hide_devs: hide,

    @on('init')
    @observes('post')
    @observes('model.composeState')
    setHide() {
      this.set('hide_devs', hide);
    },
  });
}

export default {
  name: "toggle-hidedevs",
  initialize(container) {
    Composer.serializeOnCreate('hide_devs', 'hide_devs');
    const siteSettings = container.lookup('site-settings:main');
    if (siteSettings.hide_devs_enabled) {
      withPluginApi('0.1', api => initializeHideToggle(api), {
        noApi: () => priorToApi(container)
      });
    }
  }
};

```

Like mentioned in the previous post, I get the `hide_devs` variable in the `plugin.rb` file correctly, however it’s the value from when the editor was last openend, instead of when the post was created. Not sure what to listen for to make it update according the value on “post”. I’ve tried looking through the discourse source files to find an `observes` example that would trigger on “post” but I’ve not yet found one that seems to do something like that.

> [@angus](#):
>
> quick peruse of the Ember Guide to see the various hooks and methods available to you in a model, or the controller.

I’ll have a look, thanks for the suggestion!

---

_[View the full topic](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889)._
