Giter Club home page Giter Club logo

Comments (5)

jeffbaumes avatar jeffbaumes commented on May 17, 2024

I am liking it, but it seems somewhat complex that you need to check that arg.layer !== this, though I don't claim to understand the nuance required here. Also, could you just pass the string "pan" as the first argument to on()? Seems that would be more jQuery-like.

from geojs.

cjh1 avatar cjh1 commented on May 17, 2024

On Fri, Mar 14, 2014 at 8:36 AM, Jonathan Beezley
[email protected]:

In this commit 73257427325742,
I have add a jQuery like interface for binding and triggering events. The
idea is that classes will interact with each other like this (for example
panning in the layer class)

this.map().on(geo.event.pan, function (arg) {
if (arg.layer !== this) {
this.trigger(geo.event.pan, arg);
}});this.on(geo.event.pan, function (arg) {

// layer specific implementation here

this.map().trigger(geo.event.pan, arg);});

The only problem is that this kind of propagation through the tree will
have to be coded for every event type. I'm wondering if it might be useful
to add standard parent/children attributes to the object, then the mapwould copy its
layers into children and layer would put the map in parent and the
renderer in children, etc. This way we could implement this generically
in geo.object. Also, we would want to bind the triggerer to this in the
handler to prevent circular propagation. What does everyone think?

I don't have a problem with adding this if . Maybe it should be a subclass
of object though, so only those classes that need this parent/child get it?

from geojs.

jbeezley avatar jbeezley commented on May 17, 2024

The difference between this and jQuery is that we need to propagate events both up and down the tree, so we need a mechanism for preventing circular propagation. I'm up to suggestions on how to do this. Also, geo.event.pan is defined here. It is just a string, but I think the idea is to support something like namespacing in the events.

from geojs.

jbeezley avatar jbeezley commented on May 17, 2024

Okay, here is the latest interface 03e03a2.

I changed the routing as follows:

  • An event is triggered on an object.
  • If the object has a parent and the parent did not trigger the event, it propagates the event up the tree and returns (not calling its handlers).
  • It calls all of its own handlers.
  • It triggers the event on all of its children.

It seems we also need a mechanism for preventing propagation. Maybe a stopPropagation callback as an extra argument to the handler?

@cjh1 The object defaults to no parents or children, so everything will work without a tree structure; however, I'm not opposed to moving this to a subclass.

from geojs.

aashish24 avatar aashish24 commented on May 17, 2024

@jbeezley I like the idea of making it generic. So I guess this could be applied to features as well? Any thought on that? Also, I think moving the parent / child to to something like sceneObject (or something similar) would be appropriate in that case; map, layer and renderer could use that as the base class.

from geojs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.