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/
          • stores
            • addInstanceReference
            • addListReference
            • deleteInstanceReference
            • deleteListReference
            • instanceStore
            • listStore
          • crud methods
            • destroy
            • get
            • getList
            • save
          • hydrators
            • hydrateInstance
            • hydrateList
            • hydratedInstance
            • hydratedList
        • ./data/callbacks/
        • ./data/callbacks-cache/
        • ./data/combine-requests/
        • ./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
  • /
  • ./constructor/store/
  • /
  • addListReference
  • / On this page
    • addListReference

      property

      Adds a reference to a list so it can be easily looked up.

      • source

      connection.addListReference( list[, set] )

      Adds a reference to a list in the listStore. The number of references are incremented.

      Parameters

      1. list {List}:

        The list to add.

      2. set {Set}:

        The set this list represents if it can't be identified with listSet.

      Use

      The listStore contains a collection of lists created for each listSet. The listStore is used to prevent creating the same list multiple times and for identifying a list for a given set. Lists need to be added to this store for this behavior to happen. To do this, call addListReference like the following:

      // A basic connection:
      var todoConnection = connect([
        require("can-connect/constructor/store/store"),
        require("can-connect/constructor/constructor"),
        require("can-connect/data/url/url")
      ], {
        url: "/todos"
      });
      
      var dueToday;
      
      // Get a todo:
      todoConnection.getList({due: "today"}).then(function( todos ){
      
        // Add it to the store
        todoConnection.addListReference(todos, {due: "today"});
        dueToday = todos;
      });
      

      Now, if you were to retrieve the same data sometime later, it would be the same list.

      todoConnection.get({due: "today"}).then(function( todos ){
      
        todos === dueToday //-> true
      });
      

      The .getListData response data is passed with dueToday to updatedList which can update dueToday with the new data.

      All these lists stay in memory. Use deleteListReference to remove them.

      Typically, addListReference is called when something expresses interest in the list, such as an event binding, and deleteListReference is called when interest is removed.

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