DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
      • behaviors
        • ./base/
        • ./cache-requests/
        • ./can/map/
        • ./can/ref/
        • ./constructor/callbacks-once/
        • ./constructor/
        • ./constructor/store/
        • ./data/callbacks/
        • ./data/callbacks-cache/
        • ./data/combine-requests/
          • types
            • PendingRequest
          • options
            • time
          • data methods
            • getListData
          • algebra methods
            • getSubset
            • unionPendingRequests
        • ./data/localstorage-cache/
        • ./data/memory-cache/
        • ./data/parse/
        • ./data/url/
        • ./data/worker/
        • ./fall-through-cache/
        • ./real-time/
      • modules
        • ./can/base-map/
        • ./can/model/
        • ./can/super-map/
        • ./can/tag/
        • ./helpers/weak-reference-map
      • data types
        • DataInterface
        • Instance
        • InstanceInterface
        • List
        • ListData
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-connect
  • /
  • ./data/combine-requests/
  • / On this page
    • can-connect/data/combine-requests/combine-requests

      module

      Combines multiple incoming requests into one if possible.

      • source

      dataCombineRequests( baseConnection )

      Overwrites getListData to collect the requested sets for some time. Once that time has expired, it tries to take the union of those sets. It makes requests with those unioned sets. Once the unioned set data has returned, the original requests re satisified by getting subsets of the unioned set data.

      Use

      Create a connection with the combine-requests plugin like:

      var todosConnection = connect([
        require("can-connect/data/combine-requests/combine-requests"),
        require("can-connect/data/url/url")
      ],{
        url: "/todos"
      });
      

      By default, the following will only make a single request if made at the same time:

      todosConnection.getListData({})
      todosConnection.getListData({userId: 5});
      todosConnection.getListData({userId: 5, type: "critical"});
      

      This is because can-set knows that {userId: 5, type: "critical"} and {userId: 5} are subsets of {}.

      For more advanced combining, use set algebra. The following supports combining ranges:

      var todosConnection = connect([
        require("can-connect/data/combine-requests/combine-requests"),
        require("can-connect/data/url/url")
      ],{
        url: "/todos",
        algebra: new Algebra(set.props.range("start","end"))
      });
      

      Now the following will make single request:

      todosConnection.getListData({start: 0, end: 49})
      todosConnection.getListData({start: 0, end: 5});
      todosConnection.getListData({start: 50, end: 99});
      

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