Git Product home page Git Product logo

Comments (10)

LucidCrux avatar LucidCrux commented on May 26, 2024

Doesn't seem like anyone cares much, but thought I'd update and say I'm having problems. I got ahead of myself with a new language and didn't even think about how much more ugly it is to debug with jquery and page element stuff mixed in. Much much worse than just c or .net. On plus side, I am getting extremely familiar with the code so hopefully future endeavors will be easier.

from adarkroom.

LucidCrux avatar LucidCrux commented on May 26, 2024

Put up a new stableish version of the state manager. If anyone is actually following this and doesn't mind, please go ahead and try to break it. If you know how to hunt for memory leaks, feel free to do that as well. ; P

from adarkroom.

Cogito avatar Cogito commented on May 26, 2024

I'm following. Probably worth linking to your code in a comment so people can see what it is you're working on quickly :)

from adarkroom.

LucidCrux avatar LucidCrux commented on May 26, 2024

Link to the commit: LucidCrux@db4a346

from adarkroom.

Continuities avatar Continuities commented on May 26, 2024

The function you're looking for is $.trigger()
http://api.jquery.com/trigger/

On 24 July 2013 03:44, LucidCrux [email protected] wrote:

I thought I understood javascript events, but apparently not. I am not
able to get event listeners to work as I'd like.

If I do jquery:
$(document).on('stateUpdate', $Room.updateHandler);
then it works fine, but I can't do either
$(Room).on(stuff);
or
Room.addEventListerner(stuff);

The first does absolutely nothing, the second gives .addEventListerner is
not a function error.

I know this isn't a help forum, but I've googled for hours and can't
figure it out. I found something that said .addEventListener only works on
objects that implement EventListener, something about handleEvent, and
something about functions automatically implementing EventListener. Nothing
on how to make an object implement it. Is there no way to add listeners to
javascript objects that aren't functions? Am I going to have to create an
event handler object, or use 'document' and have it call handlers in the
objects? That seems really ugly.


Reply to this email directly or view it on GitHubhttps://github.com/Continuities/adarkroom/issues/45#issuecomment-21468646
.

con-ti-nu-i-ty
n. pl. con-ti-nu-i-ties

  1. The state or quality of being continuous.
  2. An uninterrupted succession or flow; a coherent whole.

from adarkroom.

LucidCrux avatar LucidCrux commented on May 26, 2024

Sorry, I removed my question because I got help on stackoverflow, and was trying not to muddy this.

But no, .trigger is not the issue I'm having. I can trigger an event fine, the problem is that the objects (Room, Outside, Path, etc) cannot have listeners registered to them by either $(Room).on(stuff) or by Room.addEventListener(stuff). The problem as explained to me is that these are just javascript objects, not DOM objects. If you know how to do that okay, but on SO, they basically said it is impossible without a new framework, which I don't want do add. Instead I'll have to go with a subscriber system, something like:

var thing = { //The statemanager
    callbacks: {},
    regCallback: function (key, which) {
        callbacks[key] = which;
    },
    remCallback: function (key) {
        callbacks[key].delete;
    }
    update: function(e) {
        for(var i = 0, len = callbacks.length; i < len;i++){
            callbacks[i](e);
        };
    }
};

var Room = {
    updateHandler: function (e) {
        //handle stuff
    },
    subscribe: function (which, callback) {
        which.regCallback('room', callback);
    }
    unsub: function (which) {
        which.remCallback('room');
    }
};

//wherever/whenever I need to get updates something like
Room.subscribe(thing, Room.updateHandler);
//unsub
Room.unsub(thing);

If I am just missing something obvious, or didn't ask the right question on SO and you think you know how to do it, please let me know. Here is the link to SO: http://stackoverflow.com/questions/17829660/how-to-attach-an-event-listener-to-a-javascript-var?noredirect=1#comment26024386_17829660

from adarkroom.

Continuities avatar Continuities commented on May 26, 2024

Nope, you're not missing anything. I had a brain-fart. Something like what
you've written above would definitely do the trick.

On 24 July 2013 14:13, LucidCrux [email protected] wrote:

Sorry, I removed my question because I got help on stackoverflow, and was
trying not to muddy this.

But no, .trigger is not the issue I'm having. I can trigger an event fine,
the problem is that the objects (Room, Outside, Path, etc) cannot have
listeners registered to them by either $(Room).on(stuff) or by
Room.addEventListener(stuff). The problem as explained to me is that these
are just javascript objects, not DOM objects. If you know how to do that
okay, but on SO, they basically said it is impossible without a new
framework, which I don't want do add. Instead I'll have to go with a
subscriber system, something like:

var thing = { //The statemanager
callbacks: {},
regCallback: function (key, which) {
callbacks[key] = which;
},
remCallback: function (key) {
callbacks[key].delete;
}
update: function(e) {
for(var i = 0, len = callbacks.length; i < len;i++){
callbacksi;
};
}};
var Room = {
updateHandler: function (e) {
//handle stuff
},
subscribe: function (which, callback) {
which.regCallback('room', callback);
}
unsub: function (which) {
which.remCallback('room');
}};
//wherever/whenever I need to get updates something likeRoom.subscribe(thing, Room.updateHandler);//unsubRoom.unsub(thing);

If I am just missing something obvious, or didn't ask the right question
on SO and you think you know how to do it, please let me know. Here is the
link to SO:
http://stackoverflow.com/questions/17829660/how-to-attach-an-event-listener-to-a-javascript-var?noredirect=1#comment26024386_17829660


Reply to this email directly or view it on GitHubhttps://github.com/Continuities/adarkroom/issues/45#issuecomment-21504623
.

con-ti-nu-i-ty
n. pl. con-ti-nu-i-ties

  1. The state or quality of being continuous.
  2. An uninterrupted succession or flow; a coherent whole.

from adarkroom.

rgravina avatar rgravina commented on May 26, 2024

Just wondering, it seems that StateManager was merged in in this pull request. https://github.com/Continuities/adarkroom/pull/50

Is this referring to a different issue, i.e. adding something further to the state manager? Or is the TODO at the top of engine.js now out of date?

from adarkroom.

LucidCrux avatar LucidCrux commented on May 26, 2024

It was a long time ago, but I think this was taken care of. So the todo may just be out of date.

from adarkroom.

groteworld avatar groteworld commented on May 26, 2024

From what I can tell this was resolved already, so I'm removing the TODO.

from adarkroom.

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.