* jQuery.Hive.Pollen JavaScript Library

* http://github.com/rwldrn

* http://pollenjs.com

* Copyright 2010, Rick Waldron

* Dual licensed under the MIT or GPL Version 2 licenses.

* v0.1.95

* (see source for other credits)

* $.now([uts]) -> Microseconds or UTS

* $.noop() -> Empty function, Lifted from jQuery 1.4+, returns empty function (replaced $.emptyFn())

* $.bind( function, context, args ) -> Function with explicit context, context sets 'this'

* $.isObj( arg ) -> Boolean, object was created with {} or new Object()

* $.isEmptyObj( arg ) -> Boolean, Empty Object

* $.isArr( arg ) -> Boolean, Array

* $.isRegExp( arg ) -> Boolean, Regular Expression

* $.isFn( arg ) -> Boolean, Function

* $.isStr( arg ) -> Boolean, String

* $.isNum( arg ) -> Boolean, Number

* $.isJson( arg ) -> Boolean, Valid JSON String

* $.isDef( arg ) -> Boolean, Defined

* $.isNull( arg ) -> Boolean, Null

* $.isEmpty( arg ) -> Boolean, ''

* $.eq( arg, array ) -> Arg is equal to at least one definition in array

* $.trim( arg ) -> Removes all L and R whitespace

* $.inStr( arg ) -> Boolean, arg in string

* $.each( object, function ) -> Enumerate [object] (object,array), apply [function]

* $.toArray( arg ) -> Convert [arg] into an array

* $.isAtIndex( array, index, needle ) -> Boolean, Checks if [needle] is located at [index] in [array]

* $.getIndex( array, needle ) -> Int, index of [needle] in [array]

* $.inArr( array, needle ) -> Boolean, true if [needle] in [array]

* $.clone( arg ) -> Array || Object, clone of [array] or Object, deep clone of [object]

* $.last( array ) -> Array Item, last item in [array]

* $.first( array ) -> Array Item, first item in [array]

* $.unique( arg ) -> Array || Object, removes duplicate values from [arg](array||object), returns uniques

* $.merge( arr, * ) -> Array, Merges [*](array), removes duplicate values

* $.combine( keys, values ) -> Object, An object, where [keys](array) = [values](array)

* $.filter( arg , function, iteration ) -> (Array||Object), apply [function](true||false) to each item in [arg], return (array||object) of true

* $.map( array, function ) -> Array, apply [function] to each item in [array], return array of new values

* $.grep( array, expression, function ) -> Object, values that match [expression] and/or [function]

* $.size( array ) -> Int, size of arr

* $.extend( object, _object ) -> Object, copy properties fron [_object] to [object]

* $.ajax.get( request ) -> Implemented. Documention incomplete.
* --> request.url -> url to open
* --> request.data -> params
* --> request.success -> success callback

* $.ajax.post( request ) -> Implemented. Documention incomplete.
* --> request.url -> url to open
* --> request.data -> params
* --> request.success -> success callback

* $.param( arg ) -> String, Derived and Adapted from, similar in behavior to jQuery.param()

* $.storage( key, val ) -> ?, persistant across worker messages (by worker) data storage - setter

* $.storage( key ) -> Val, persistant across worker messages (by worker) data storage - getters

* $.query( selector, object ) -> *, Query json or object with JSONPath selector
* --> http://goessner.net/articles/JsonPath/

* $.send( message ) -> Wraps and normalizes postMessage() across supporting clients, sends [message](object||string||array) to client
* --> if [message] is an object, and message.SEND_TO & message.SEND_FROM is defined, the message will be sent directly to the worker defined by SEND_TO

* $.receive( function ) -> Worker, execute [function] when worker receives a message from the client
* --> first argument is message object
* --> 'this' is WorkerGlobalScope
* --> can be shortened to $(function (message) { } );

* $.decode( arg ) -> JSON as String, turns JSON [arg] into a str

* $.encode( arg ) -> JSON Object, turns [arg] into JSON
Basic Worker setup:

importScripts('jquery.hive.pollen.js');

$(function (data) {
  
  // `this` equals WorkerGlobalScope
  
  $.ajax.get({  
    url: 'get-data-from-the-server.php',  
    dataType:'json', 
    data: $.param(data.message), 
    success: function(jsonObj) { 

      //  Assume its a list of companies with some contact data.

      $.send( 
        $.unique( 
          $.filter(jsonObj, function (obj) { 
            //  If not passed in the data property above, we could filter here.
            //  Not the most efficient way, the example is really to illustrate Pollen's syntax
            
            if ( $.inStr(obj.company, data.company) ) { 
              return true; 
            } 
            return false;
          })
        )
      );
      
      // OR...
      
      $.send( 
        $.query(
          //  Get filtered data with a JSONPath query
          "?company='"+data.company+"'", 
          jsonObj
        )
      );
    } 
  });      


});


PollenJS Logo © Nick Piava 2010