Comments (10)
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.
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.
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.
Link to the commit: LucidCrux@db4a346
from adarkroom.
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
- The state or quality of being continuous.
- An uninterrupted succession or flow; a coherent whole.
from adarkroom.
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.
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
- The state or quality of being continuous.
- An uninterrupted succession or flow; a coherent whole.
from adarkroom.
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.
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.
From what I can tell this was resolved already, so I'm removing the TODO.
from adarkroom.
Related Issues (20)
- When you buy a map while your world is fully uncovered, the game crashes HOT 2
- URL to candybox is dead HOT 4
- Audio won't after changing language
- Data corrupted and game UI not show after fur storage keep growing and I refreshed the page HOT 1
- Encounter Tier 1 music loops incorrectly
- Hyper mode is on by default it seems HOT 2
- When attacking, only the first two sounds of each weapon type are used, not the third HOT 1
- Missing () HOT 1
- Bolas stun appears to be permanent HOT 2
- Translation not working | strings.js from strings.po file? HOT 1
- Can't Use Machine in Engineering Wing HOT 2
- Bug: Inventory view doesn't show 3+ rows of items HOT 2
- the issues of language
- Combat buttons not showing up properly HOT 2
- Make chat log scrollable HOT 6
- Cured meat at outposts should consume from home storage
- Games
- Typo: 'disintigrate'
- Creating/buying the compass brakes the game HOT 10
- Can't embark on A Dusty Path even with a compass HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adarkroom.