Thanks *Jared*, that makes sense

AppView now passes an object like so...

        window.App = new AppView({
                $searchresults: $("body > ul"),
                $favourites : $("footer ul"),
                $input          : $("form input"),
                $body           : $("body"),
                $preview        : $("article")

});

and call them through *this.options* e.g....
*
*
*this.options.$body.addClass('results'); *
*
*
However its not totally DOM independent as i'm still manipulating the class
names. Is there an alternative to this?

FYI: I've rewritten the script using knockout.js (
http://mrswitch.github.com/pic-n-flick/knockout/) which has been awesome,
i've been able to totally remove any DOM operations from my script.js file.
Perhaps this is easy to achieve in backbone?

A


On Mon, Nov 14, 2011 at 10:18 PM, Jared Hirsch <[email protected]>wrote:

> The search function could use a little love. You want to pass nodes into
> the view constructor, rather than hard-code selectors all over the place.
> This lets you unit test your code without a real DOM.
>
> Think in terms of separating DOM access, network IO, and your
> transformation logic on the returned JSON. This is the start of splitting
> out concerns. If you try to figure out how you could test different parts
> without the network (encapsulate IO in an object, swap out a mock) or the
> DOM (a DOM node abstraction), you'll start to naturally break the code into
> pieces that are MVCish.
>
> Hope this helps a little
>
> Jared
>
> On Nov 9, 2011 6:17 PM, "Andrew Dodson" <[email protected]> wrote:
>
> Hello, any one know much about MVC patterns in JavaScript? + have 5
> minutes to read a little code?
>
> *demo*: http://mrswitch.github.com/pic-n-flick/
>
> There is only one file doing the work.
>
> *script*: https://github.com/MrSwitch/pic-n-flick/blob/master/js/script.js
>
>
> I haven't had much experience with MVC structure and this is my first kick
> about with Backbone.js.
> I had a lot of problems with it. And was totally stumped trying to manage
> two Views or even two collections+models firing the correct triggers on the
> right Views... it all got a bit messy there. I hence shelved the first
> attempt at
> https://github.com/MrSwitch/pic-n-flick/blob/master/js/script_kaput.js
>
> I also couldn't bind an event to the *window* object via backbone's
> delegateEvents<http://documentcloud.github.com/backbone/#View-delegateEvents>,
> without hacking it separatly.
>
> Any insight into the sobering world of MVC or backbone would be fantastic.
>
> A
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
>  --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to