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/
          • algebra
          • cacheConnection
          • id
          • idProp
          • listSet
          • listSetProp
        • ./cache-requests/
        • ./can/map/
        • ./can/ref/
        • ./constructor/callbacks-once/
        • ./constructor/
        • ./constructor/store/
        • ./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
  • /
  • ./base/
  • /
  • id
  • / On this page
    • id

      function

      Uniquely identify an instance or raw instance data.

      • source

      connection.id(instance)

      Returns the idProp if it exists, otherwise the algebra's id values, otherwise the id property.

      Parameters

      1. instance {Instance|Object}:

        The instance or raw props for an instance.

      Returns

      {String|Number}:

      A string or number uniquely representing instance.

      Use

      Many extensions, such as the can-connect/constructor/store/store, need to have a unique identifier for an instance or instance data. The connection.id method should return that.

      Typically, an item's id is a simply propertly value on the object. For example, todo data might look like:

      {_id: 5, name: "do the dishes"}
      

      In this case, algebra's id comparator should be set to "_id" like:

      var algebra = new set.Algebra({
        set.comparators.id("_id")
      });
      connect([...],{algebra: algebra});
      

      However, some data sources have compound ids. For example, "Class Assignment" connection might be represented by two properties, the studentId and the classId. For this kind of setup, you can provide your own id function as follows:

      var classAssignmentConnection = connect(['data-url'],{
        url: "/class_assignments",
        id: function(classAssignment){
          return classAssignment.studentId+"-"+classAssignment.classId;
        }
      });
      

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