Section 14.1. How to Use This Chapter


14.1. How to Use This Chapter

MochiKit comes with very good documentation. But, it's reference documentation. It tells you what you need to know to use a specific function. That's certainly valuable, and this chapter doesn't try to reproduce that.

The goal of this chapter is to provide more background around the features of MochiKit with the perspective of Python programmers in mind.

The next section of the chapter covers MochiKit.Base, which are the lowest-level functions within MochiKit. We start off with the low-level functions and work our way up to the high-level ones, which tend to build on the low-level ones. If you want, you can jump on to the later sections of the chapter, but be aware that you may need to bounce back to pick up on functions that are used in those sections. Also, there are many useful functions in MochiKit.Base that can help you with your JavaScript tasks.

Note

At the time of this writing, MochiKit 1.4 has not yet been released. Much of the development appears to have been done already, but it is possible that there will be some variation between the functions presented here and the final 1.4 version. This will be most true for MochiKit.Style and MochiKit.Visual.


14.1.1. MochiKit's Packaging

MochiKit is packaged up as a single, packed MochiKit.js file that contains all of the features. Note, however, that the features covered in "The Wow Factor" section of Chapter 15, "Effective Ajax with MochiKit," have not yet been packaged into a full MochiKit.js. You can use those modules separately now and you will still be able to do so after MochiKit 1.4 is released.

In addition to the single .js file format, you can use just the parts of MochiKit that you need. MochiKit's documentation provides a clear indication for each module of which modules are required, and MochiKit makes sure that the requirements are met. If you use MochiKit.Iter without including MochiKit.Base, for example, an exception is thrown.

The names of MochiKit's functions are put into their own namespaces for maximum compatibility. MochiKit's Base.js file, for example, places all of its functions into MochiKit.Base. When you use the MochiKit.js file in your project, the public functions are all put into the global JavaScript namespace. That is a nice convenience that saves on typing. (You can type getElement rather than MochiKit.DOM.getElement.)

MochiKit is expressly designed to work with JavaScript Archive Network (JSAN) and the Dojo Toolkit. Dojo's style is to namespace all the calls (for example, dojo.io.bind), and MochiKit sticks to that when used with Dojo's packaging system. Using MochiKit with Dojo means that you should use the full name (MochiKit.DOM.getElement) for functions that you access.

14.1.2. MochiKit's Interactive Shell

MochiKit provides an interactive shell demo that lets you interactively run JavaScript commands to do the same kind of ad-hoc testing and debugging you can do from the Python prompt. This is a great way to familiarize yourself with MochiKit and just play with the functions that it has to offer. Many of the examples given in this chapter are done from within the interactive interpreter.

The examples in this chapter can all work within the "mochiexamples" project that comes with this book (www.turbogearsbook.com). To try these examples, go into the mochiexamples directory and run the following:

  ./start-mochiexamples.py


You'll find the interactive interpreter at http://localhost:8080/interpreter.




Rapid Web Applications with TurboGears(c) Using Python to Create Ajax-Powered Sites
Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites
ISBN: 0132433885
EAN: 2147483647
Year: 2006
Pages: 202

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net