Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8630085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:58:24+00:00 2026-06-12T08:58:24+00:00

What I am trying to do: Imagine in the browser there is an array

  • 0

What I am trying to do:

Imagine in the browser there is an array of divs, the divs are instantiated or deleted per user request.
When left arrow or right arrow keys are pressed, the divs should move left or right.

My current ( poorly crafted ) solution:

Event handling and delegation:

function onDocumentKeyDown( event ){
     switch ( event.keyCode ){
            case 37: App.objectsView.scrollLeft(); break;
            case 39: App.objectsView.scrollRight(); break;
     }
}


// add event listener to document
function addEventListeners() {
    document.addEventListener( 'keydown', onDocumentKeyDown, false );
}
addEventListeners();

Application container view:

App.objectsView = Ember.ContainerView.create({

    childViews: [],

    // CRUD stuff
    createView: function(){ ... },

    deleteView: function(){ ... }, 

    updateView: function(){ ... },

    // navigation stuff
    scrollRight: function(){
        this.scroll('right')
    },

    scrollLeft: function(){
        this.scroll('left')
    },

    scroll: function( direction ){
        this.get('childViews').forEach( function( key ){
            var object = key;
            object.move( direction );
        }, this)
    },


});

Application view class ( for completeness, not really that relevant ):

App.ObjectView = Ember.View.extend( Animation, {

    ...

    move: function( param ){ ... }

});

*Note, most of the dom selection and change css attribute logic is brought into the view via an Animation mixin.

As you could see, I really don’t like this implementation because:

  1. Each key event is bound to to a specific function in container view, what if I want key 37 to do one thing in some context and something else in another context ( for example where the mouse arrow is )?

  2. The onDocumentKeyDown function is added to the document, I can’t exactly say why but it looks jarring to me.

  3. ObjectsView has both logic that manages instantiation and event delegation. Is the containerView in Ember even meant to handle navigation logic at all? ( I could separate them into two different functions, but if the events are handled the same way, then they seem to be morally equivalent solutions ).

Are there any commonly used patterns in Ember or just any JS MV* framework that handle key event via some sort of single instance central hub, and then propagate to other parts of the system per application state? And this Ember router concept, does that fit in here somehow?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:58:26+00:00Added an answer on June 12, 2026 at 8:58 am

    For handling keyboard events with Ember, we have drawn on the EventManager implementation from Flame.js. Perhaps you can take similar inspiration: https://github.com/flamejs/flame.js/blob/master/mixins/event_manager.js

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove duplicate elements from an excel array. I imagine I'm
I am trying to write a gsub for a regex match, but I imagine
I am having trouble trying to get iterators for inner sub-containers. Basically imagine this
I have the simplest PhoneGap app one could imagine! All I'm trying to do
It's quite hard to explain what I'm trying to do, I'll try: Imagine a
I am trying to do the following. Imagine you are reading some LINQ article
Let's imagine really simple game... We have a labirinth and two players trying to
I'm trying to get a program I'm writing (in F#, though I would imagine
This question is part user experience, part engineering. I am trying to find a
I'm trying to do the following: Imagine you have a Java EE application running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.