In a Discourse development discussion, users explore the difference between .hbs and .raw.hbs (or .hbr) Handlebars templates. net_deamon notes that some plugin outlets (like topic-list-after-title) use {{raw-plugin-outlet}}, requiring .raw.hbs files, while others use {{plugin-outlet}} with standard .hbs files. sam clarifies that raw templates are a performance optimization—they lack full Ember lifecycle features like setupComponent, making them faster but less flexible. spirobel asks about alternatives to setupComponent and computed properties in raw templates; they later find a workaround by reopening models to add computed properties accessible in .raw.hbs. merefield questions whether raw templates can be backed by JavaScript components like regular ones. They discover that some components (e.g., topic-list-item) use .hbs templates that render .hbr templates via JavaScript, suggesting raw templates don’t directly support JS unless manually bridged. markvanlan recommends using helpers for JS logic in raw templates, citing an example from the discourse-category-experts plugin. merefield reports switching some .hbr to .hbs to enable closure actions for passing data up the component tree, despite performance trade-offs. markvanlan and merefield discuss whether helpers can handle upward data flow, with merefield noting the need to persist computed image properties from leaf components to grandparent for styling. In summary, raw templates offer speed but limited interactivity; JS logic must be added via helpers or model extensions, or avoided by using full .hbs components when complex data flow is needed.
هل يوجد شيء مشابه لـ setupComponent(args, component) مع المنافذ الخام أيضًا؟ ماذا عن الخصائص المحسوبة؟ أود إجراء بعض الحسابات بناءً على البيانات الموجودة في السياق. كيف يمكنني القيام بذلك؟ لا أعرف حتى ما إذا كان اسم ملف .js.es6 المرافق الذي أنشأته صحيحًا. هل يجب أن أسميه .raw.js.es6؟
هذا المراقب ليس مثاليًا، حيث نسعى للتخلص منه مع استمرارنا في ترقية Ember. أعتقد أن الطريقة الأفضل هي إنشاء دالة مساعدة (helper) ووضع كود JavaScript الخاص بك فيها. إليك مثالًا:
في بعض الأعمال الأخيرة، احتجت إلى أن تكون بعض “شجرة” القوالب قادرة على نقل البيانات من قالب ورقة باستخدام إجراءات الإغلاق، لذا قمت بتحويل بعض ملفات hbr إلى hbs لدعم ذلك.
هذا العمل تجريبي وأقدر أن له تأثيرًا على الأداء، لكن بعد تكرار التصميم عدة مرات لم أستطع إيجاد طريقة بديلة للقيام بذلك مع البقاء “داخل الإطار”.
على وجه التحديد، أقوم بتحديد خصائص صورة في مكون ورقة، ثم تخزينها كخصائص للجد الأكبر للتأثير على التنسيقات التي يجب أن تستمر بعد عملية عرض القائمة الحالية. يجب بالتأكيد نقل البيانات إلى الأعلى. إذا كان بإمكان دالة مساعدة تحقيق ذلك، فذلك يبدو خيارًا جيدًا إذا واجهت صعوبة مع النهج الحالي، شكرًا لك!