DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
    • can-stream
    • can-vdom
    • can-view-import
    • can-zone
      • types
        • ZoneSpec
        • makeZoneSpec
      • static
        • current
        • error
        • ignore
        • waitFor
      • prototype
        • addWait
        • data
        • removeWait
        • run
      • plugins
        • ./debug
        • ./timeout
      • modules
        • ./register
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-zone
  • /
  • makeZoneSpec
  • / On this page
    • makeZoneSpec

      typedef

      A function that returns a ZoneSpec object. This can be used any place where a ZoneSpec is accepted.

      • source

      function(data)

      Parameters

      1. data {data}:

        The Zone's data object, useful when you want to append data to the Zone.

        This examples wraps document.createElement to keep count of how many elements are created, and appends the count to data when the Zone ends.

        var mySpec = function(data){
            var realCreateElement,
                count = 0;
        
            return {
                beforeTask: function(){
                    realCreateElement = document.createElement;
                    document.createElement = function(){
                        count++;
                        return realCreateElement.apply(this, arguments);
                    };
                },
                afterTask: function(){
                    document.createElement = realCreateElement;
                },
                ended: function(){
                    data.elementsCreated = count;
                }
            };
        };
        
        var zone = new Zone(mySpec);
        
        zone.run(function(){
            // Do stuff here
        })
        .then(function(data){
            data.elementsCreated; // -> 5
        });
        

      Returns

      {ZoneSpec}:

      A ZoneSpec

      Using a function rather than a ZoneSpec object gives you a closure where you can store local variables that will be specific to the Zone you are running in.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.