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/
        • ./data/localstorage-cache/
        • ./data/memory-cache/
        • ./data/parse/
          • parseInstanceData
          • parseListData
          • parseListProp
          • parseInstanceProp
        • ./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/parse/
  • /
  • parseInstanceData
  • / On this page
    • parseInstanceData

      function

      Returns the properties that should be used to make an instance given the results of getData, createData, updateData, and destroyData.

      • source

      connection.parseInstanceData(responseData)

      This function will use parseInstanceProp to find the data object representing the instance that will be created.

      Parameters

      1. responseData {Object}:

        The response data from getData, createData, or updateData.

      Returns

      {Object}:

      The data that should be passed to hydrateInstance.

      Use

      parseInstanceData comes in handy when dealing with an irregular API that can be improved with data transformation.

      Suppose a request to /services/todos returns:

      {
        baseUrl: "/proxy/share",
        todo: {
          id: 0,
          name: "dishes",
          friendFaceUrl: "friendface?id=0",
          fiddlerUrl: "fiddler?id=0"
        }
      }
      

      The baseUrl property is meta-data that needs to be incorporated into the instance data. One way to deal with this is:

      connect([
        require("can-connect/data/parse/parse"),
        require("can-connect/data/url/url")
      ],{
        parseInstanceProp: "todo",
        parseInstanceData(responseData) {
          ['friendFaceUrl', 'fiddlerUrl'].map(urlProp => {
            responseData.todo[urlProp] = [
              responseData.baseUrl,
              responseData.todo[urlProp]
            ].join('/');
          });
      
          return responseData;
        }
      })
      

      This results in an object like:

      {
        id: 0,
        name: "dishes",
        friendFaceUrl: "/proxy/share/friendface?id=0",
        fiddlerUrl: "/proxy/share/fiddler?id=0"
      }
      

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