Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
site-wide/"globally used" behaviors (best practice)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rolf-nl  
View profile  
 More options Feb 27 2012, 5:36 pm
From: Rolf-nl <plentyofr...@gmail.com>
Date: Mon, 27 Feb 2012 14:36:53 -0800 (PST)
Local: Mon, Feb 27 2012 5:36 pm
Subject: site-wide/"globally used" behaviors (best practice)
If you have some site-wide code/classes you want to use "globally",
(eg. LogSystem, CookieMonster, Storage, SuperFancyFX) are you adding
these to the dom in the first element after <body> for example, or
how?

That is what I have now, like using a wrapper div that's already
present for this behavior container <body><div id="wrapper" data-
behavior="Prefs Storage">...</div></body>

Then in other behaviors I use api.fireEvent('ThisBehaviorUpdated',
[foo, bar]) to broadcast and some behavior declared in this wrapper-
div can pick stuff up whenever it's needed.

Makes sense? Or wrooooong implementation?

Rolf


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Newton  
View profile  
 More options Feb 27 2012, 5:57 pm
From: Aaron Newton <anut...@gmail.com>
Date: Mon, 27 Feb 2012 14:57:16 -0800
Local: Mon, Feb 27 2012 5:57 pm
Subject: Re: site-wide/"globally used" behaviors (best practice)

Behaviors generally speaking are used only to decorate elements on the
page. If you have a behavior that needs to refer to some global property
(user data for example) I'd use the passMethod/passMethods argument to pass
in getters for them to your filters. So your filter can do
api.get('userdata') or whatever. Now you can easily search for and support
that API.

But putting behaviors on the document body doesn't really get you anything
(unless you are really decorating the body). Instead, I'd instantiate these
things and then pass them to behavior. Like so:

var user = new User(...);
var storage = new Storage(...);

var b = new Behavior();
b.passMethods({
  getUser: Function.from(user),
  getStorage: Function.from(storage)

});

b.apply(document.body);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rolf-nl  
View profile  
 More options Feb 28 2012, 3:41 pm
From: Rolf-nl <plentyofr...@gmail.com>
Date: Tue, 28 Feb 2012 12:41:07 -0800 (PST)
Local: Tues, Feb 28 2012 3:41 pm
Subject: Re: site-wide/"globally used" behaviors (best practice)
before closing textmate yesterday evening I added "//check Behavior
Method: passMethod {#Behavior:passMethod}" to some of my testing
crapness so I was sort of on a right track but not there yet. Your
last example seems much more usable indeed; I was using an element to
instantiate something for the sake of it being the "parent" element..
wrooong!

More later

On Feb 27, 11:57 pm, Aaron Newton <anut...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »