Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9322

Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts?

From Matt Kruse <matt@thekrusefamily.com>
Newsgroups comp.lang.javascript
Subject Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts?
Date 2011-12-16 11:52 -0800
Organization http://groups.google.com
Message-ID <d219f917-c087-4826-ac38-7a2a33856df2@o7g2000yqk.googlegroups.com> (permalink)
References <871e8802-8613-4796-93f1-5be9d1cbf2a4@32g2000yqp.googlegroups.com> <77574625-74ed-4b94-90a0-a0e8ae65cc68@p9g2000vbb.googlegroups.com> <f6f03e8d-b1fb-4377-b47d-a1610f251832@s26g2000yqd.googlegroups.com> <96de9d5b-a255-4244-a54d-5ee3d11b07fa@o9g2000vbc.googlegroups.com>

Show all headers | View raw


On Dec 16, 1:23 pm, Scott Sauyet <scott.sau...@gmail.com> wrote:
> Matt Kruse wrote:
> > I'm curious why you would not just want to inspect the data in the
> > subscriber function itself?
> For the same reason that you wouldn't want to send all messages to all
> subscribers, and let them sort it out by checking the topic string
> themselves.

Point taken. I think I will save this on my list of ideas for version
2.

> Okay, but be careful of bloating things by allowing both array and
> delimited string options.

Internally, I just .split() the string into an array anyway, so I
wrapped that with
   if (typeof messages=="string")
and now it accepts both.

I don't mind limiting messages and saying they cannot have spaces or
commas. That seems reasonable. And this adds a little flexibility.

In my code, I actually write this often, when an array is needed:

"a,b,c,d".split(/,/)

For multiple values, I find it clearer, easier and less error-prone
than matching up lots of quotes and commas.

> > But I also see your point - publishers should really only publish
> > persisted messages if they really need to be persisted, right? And the
> > subscriber shouldn't have to care either way?
> Yes, and it's a little awkward either way.

Agreed. Here's my compromise - subscribers will by default get all
persisted messages. They can supply an option to not get them. Seems
fair.

> > Nope, I am calling setTimeout() on each subscrber, with a delay of
> > 10ms for the first, 11 for the second, 12, etc. That's why it can't be
> > canceled. It's really de-coupling all the subscribers.
> What's the advantage of this over simply delaying the execution of the
> entire block of subscribers?

Well, if one breaks, it won't prevent the next from running. Also, the
first function won't be prevented from updating the UI by a long-
running subsequent subscriber. Its UI changes will be reflected in the
browser as soon as it exits.

> >> Also, should publishers be allowed to declare that they
> >> are to be run asynchonously?  Obviously they could do that internally
> >> in their functions, but wouldn't it be nice to do it in the Arbiter?
> > You mean subscribers? If so, then yes, that's a good idea too.
> Yes, subscribers.  "When I hear my topic announced, I'm going to go do
> some complicated Ajax magic.  Don't wait up."  :-)

Just implemented it. Thanks :)

> > Will post soon. I have it running, just not in a form that I want to
> > publish to the world yet ;)
> Sounds like most of my code!

I hear ya! Code never seems finished enough to post for public use.
I'm reminded of the slogan they have on the walls at Facebook - "Done
is better than Perfect".
I'm not sure I agree with the tone of that, but in some respects I
like it :)

Matt

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Arbiter.js - my Pub/Sub implementation API. Any thoughts? Matt Kruse <matt@thekrusefamily.com> - 2011-12-15 11:52 -0800
  Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Stefan Weiss <krewecherl@gmail.com> - 2011-12-16 03:06 +0100
    Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Matt Kruse <matt@thekrusefamily.com> - 2011-12-15 22:13 -0800
      Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Stefan Weiss <krewecherl@gmail.com> - 2011-12-16 21:34 +0100
  Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Scott Sauyet <scott.sauyet@gmail.com> - 2011-12-16 06:10 -0800
    Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Matt Kruse <matt@thekrusefamily.com> - 2011-12-16 07:09 -0800
      Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Scott Sauyet <scott.sauyet@gmail.com> - 2011-12-16 11:23 -0800
        Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Matt Kruse <matt@thekrusefamily.com> - 2011-12-16 11:52 -0800
        Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Matt Kruse <matt@thekrusefamily.com> - 2011-12-18 22:55 -0800
          Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Scott Sauyet <scott.sauyet@gmail.com> - 2011-12-20 07:06 -0800
    Re: Arbiter.js - my Pub/Sub implementation API. Any thoughts? Matt Kruse <matt@thekrusefamily.com> - 2011-12-16 09:39 -0800

csiph-web