And what about the client side? Replace Drupal.behaviors by an event-based approach

Problems:

  • Drupal.behaviors is very specific of Drupal and unfamiliar to JavaScript developers, which feel comfortable with custom events
  • It's not so flexible
  • You don't have much control over the execution flow (what executes when, in which order, how)
  • It doesn't scale (performance suffers if there are many events)

Proposed solution:

  • Discuss a more robust JavaScript layer based on events

Goal:

  • Introduce new JavaScript developers to Drupal
  • Make the JavaScript layer more flexible, decoupled and modular
  • Have some semantic events
  • Allow JavaScript code to react to just some events
  • Send additional data to event callbacks
  • Improve performance
  • Have a way to control the execution order, maybe using weights or dependencies (run this after that, etc.)

There is a proof of concept in views_autorefresh, a module that is part of views_hacks. We implemented two custom events, one that triggers when new content is available (and sends the number of new items to the callbacks) and another that triggers when new content is refreshed / appended.

Schedule info
Status: 
Proposed
Session Info
Speaker(s): 
Track: 
Core Conversations
Experience level: 
Advanced