هل يمكننا إضافة إضافات Ember إلى مكون إضافي لـ Discourse؟ (مثل Ember Power Select)

I’d like to add some ember add-ons to a plugin.

Here’s an example: Ember’s Power Select.

(This helps with drop-downs. Discourse uses select-kit, which I know is also powerful, but I find it hard to customize because its heavily abstracted in the code base. So I’d like to try power select).

In a normal Rails/Ember app, I think I would just add the add-on with:

$ ember install ember-power-select

Then I’d add stuff like the following:

hbs template:

<PowerSelect @options={{this.names}} @onChange={{this.foo}} as |name|>
  {{name}}
</PowerSelect>

javascript file that goes along with it:

    import Controller from '@ember/controller';
    export default class extends Controller {
      names = ['Stefan', 'Miguel', 'Tomster', 'Pluto']
      foo() { }
    }

But a Discourse plugin is not a standard Rails app. Is there something special I need to do to get it working?

3 إعجابات

Well, I watched this wondering if you’d get any hints, but here we are 4 days later.

I’m pretty novice at Ember, but I’m fairly certain that you’ll be much better off if you manage to deal with the “heavily abstracted” stuff and play by those rules. Not only is pulling in other add-ons hard to figure out, but it’s also going to be hard to maintain.

إعجاب واحد (1)

We are upgrading Discourse over to EmberCLI, and we are pretty close to it now:

Thanks, all.

I’d seen that before, but am glad to have the confirmation that it is not possible to add Ember add-ons until that upgrade is done. So it sounds like adding ember add-ons will be possible soon–once the upgrade is complete. And that sounds great.


I think that’s an interesting question. Here’s my two cents:

In terms of using the discourse “abstracted stuff” v ember add-ons: I could be wrong, but I think that using ember add-ons for specific tasks in plugins might be easier to maintain, in the cases where you are trying to do something different than what Discourse is doing already. This is my thinking:


Example here is wanting to add a brand new drop-down in a plugin. That distinction is probably important–I’m talking here about trying to do new things in a plugin that are not done in the discourse code-base, and the question is whether to start with discourse methods or a separate add-on.

A lot of times you really don’t have a choice. For example, if I wanted to add a custom field to topics, I’d always customize on top of discourse’s pre-built methods and code.

But If its a targeted piece of functionality–like a drop-down for a new purpose–I’d already be in the case where, if I use the discourse methods, I’d be adapting them to things they weren’t targeted towards.

Option 1: I could try to take the select-kit code I see in, say, category-chooser, and insert it in a new spot (that’s not about categories), and then try to customize it to be about what I want the dropdown to be about, instead of categories. This is the task that I described earlier as being tricky.

And it could be difficult to maintain–because if the discourse team changes something in how the category-chooser select-kit code works, then that could change my new customized drop-down, but in ways that could be surprising (bc I had customized it so it works slightly differently than the actual category-choose dropdown).

Option 2: I could insert something from ember that is robust but that is also made to be customized, where I can see fairly clearly how the code actually works. In that case, I might miss out cool new features that discourse might add to its drop-downs, but I would be able to stay on top of how my drop-down works more easily. So this is probably the best option, I think, if it is possible.

Option 3: Code it entirely from scratch. That’s where I’ve been tending to end up. When the coding is done, it’s nice to have code that I fully understand and can customize. But of course it takes longer, and (the initial versions at least) are unlikely to be as powerful and robust as what the discourse team or the ember team have built.

3 إعجابات

Bump, and to add it would be great to add support for Ember add-ons to Theme Components …

6 إعجابات

Bump.
If we add addon to discourse such
cd app/assets/javascripts/ && yarn add LIB_NAME
How will this addon be available in the plugin?

أتساءل فقط ما إذا كان هذا ممكنًا في الوقت الحاضر؟ (وإذا كان الأمر كذلك، فكيف؟)

إعجابَين (2)

أخشى أن لا. يمكن إضافة إضافات Ember إلى Discourse الأساسي، ولكن ليس عبر المكونات الإضافية. قد نضيف في النهاية طريقة للمكونات الإضافية/السمات لتحديد تبعيات npm، ولكنها ليست على خارطة الطريق الفورية.

إعجابَين (2)

كنت أبحث حرفيًا عن هذا الشيء نفسه.

  • سؤال جانبي لـ David: بينما لا يمكن الوصول إليه عبر المكونات الإضافية، هل يمكننا نظريًا إضافة مكون إضافي إلى النواة ثم استخدامه في مكون إضافي إذا كنا نستضيف ذاتيًا؟ إذا كان الأمر كذلك، فكيف؟ (حاولت الإضافة إلى package.json في app/assets/javascripts/discourse ولكن لم ينجح التحميل، وأتخيل أن السبب هو أنني أفتقد شيئًا بسيطًا.)
إعجاب واحد (1)

نعم، ولكنك حقًا لا تريد نسخ Discourse المتفرع ثم محاولة سحب جميع الالتزامات. كل من فعل ذلك ندم بشدة على فعله.

هممم. ولكن إذا كان مجرد ملف واحد، يمكنك تصور أن يكون ملف app.yml الخاص بك ينسخ الملف من مكان ما إلى /var/www/discourse بعد استنساخ Discourse مباشرة. أعتقد أنني فعلت ذلك من قبل لتغيير الحدود في إعدادات الموقع.

إعجابَين (2)

نعم، كما ذكر @pfaffman، قد تتمكن من تعديله للعمل عبر بعض التعديلات على app.yml. ستحتاج إلى التأكد من إجراء التعديل قبل خطوات yarn install و assets:precompile.

ولكن هذا غير مدعوم تمامًا، وقد يؤدي إلى تعطل أشياء غير متوقعة. لا أوصي به.

من باب الفضول، ما هي الوظيفة الإضافية التي كنت تأمل في استخدامها؟

إعجابَين (2)

لم أتقدم كثيرًا في الواقع، ومع ذلك، وجدت أن معظم الإضافات الشائعة لديها وظائف موجودة بالفعل داخل Discourse نفسه. جاذبية الإضافات هي أن الوثائق بشكل عام أفضل قليلاً والموارد المتاحة إذا واجهت صعوبة تكون مفصلة جيدًا. على سبيل المثال، هناك ثروة من الوثائق والمشكلات التي تم “حلها” باستخدام ember-concurrency، لذلك إذا كنت مطورًا جديدًا، فإن الوصول إلى هذه الإضافة يعني عادةً أنه يمكنك البدء والتشغيل بسهولة أكبر.

لكن كما قلت، كان الأمر مجرد فضول أكثر من رغبة.

إعجاب واحد (1)

إذن أنت تبحث حرفيًا عن المتاعب. أوصي بعدم التفكير في أي إضافة حتى تجد أن الموارد الحالية لا تلبي احتياجاتك.

لكنك لا تعرف ما إذا كانت ستكون متوافقة مع كيفية حل Discourse لهذه المشكلة اليوم أو في المستقبل. إذا كنت تريد التطوير لـ Discourse، فإن النظر إلى أمثلة لكيفية عمل الأشياء في Discourse سيكون هو الطريق الصحيح.

لا تكن الرجل الذي يبحث عن مفاتيحه تحت المصباح بدلاً من تحت السيارة حيث أسقطها لأنه يمكنك الرؤية بشكل أفضل تحت المصباح.