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/
          • crud methods
            • destroy
            • get
            • getList
            • save
          • crud callbacks
            • createdInstance
            • destroyedInstance
            • updatedInstance
            • updatedList
          • hydrators
            • hydrateInstance
            • instance
            • list
            • hydrateList
          • serializers
            • serializeInstance
            • serializeList
          • helpers
            • cidStore
            • isNew
        • ./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
  • /
  • ./constructor/
  • /
  • instance
  • / On this page
    • instance

      property

      Returns the typed form of the raw data.

      • source

      connection.instance( props )

      Takes raw data and runs it through hydrateInstance.

      Parameters

      1. props {Object}:

      Returns

      {Instance}:

      The typed instance.

      Use

      If you have a special type with helper functions you'd like to have available, you can convert raw data to that type in instance. The following makes it so .get resolves to objects with a complete method.

      Todo = function(props){
        Object.assign(this, props);
      };
      Todo.prototype.complete = function(){
        this.completed = true;
      }
      
      var todosConnection = connect([
        require("can-connect/constructor/constructor"),
        require("can-connect/data/url/url")
      ], {
        url: "todos",
        instance: function( props ) {
          return new Todo(props);
        }
      });
      

      This allows:

      todosConnection.get({id: 5}).then(function(todo){
        todo.complete();
      });
      

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