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/
        • ./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
  • /
  • ./can/base-map/
  • / On this page
    • can-connect/can/base-map/base-map

      module

      Create connection with many of the best behaviors in can-connect and hook it up to a can-define/map/map.

      • source

      baseMap(options)

      Creates a connection with the following behaviors: can-connect/constructor/constructor, can-connect/can/map/map, can-connect/constructor/store/store, can-connect/data/callbacks/callbacks, can-connect/data/callbacks-cache/callbacks-cache, can-connect/data/parse/parse, can-connect/data/url/url, can-connect/real-time/real-time, can-connect/constructor/callbacks-once/callbacks-once.

      Use

      The can-connect/can/base-map module exports a helper function that creates a connection with the "standard" behaviors in can-connect and hooks it up to a can-define/map/map and can-define/list/list.

      If you are using CanJS, this is an easy way to create a connection that can be useful and fast in most circumstances.

      To use it, first define a Map and List constructor function:

      var Todo = DefineMap.extend({ ... });
      var TodoList = DefineList.extend({
          "#": Todo,
          ...
      });
      

      Next, call baseMap with all of the options needed by the behaviors that baseMap adds:

      var todoConnection = baseMap({
        idProp: "_id",
        Map: Todo,
        List: TodoList,
        url: "/services/todos",
        name: "todo"
      });
      

      As, can-connect/can/map/map adds CRUD methods to the Map option, you can use those to create, read, update and destroy todos:

      Todo.getList({}).then(function(todos){ ... });
      Todo.get({}).then(function(todo){ ... });
      
      new Todo({name: "dishes"}).save().then(function(todo){
        todo.attr({
            name: "Do the dishes"
          })
          .save()
          .then(function(todo){
            todo.destroy();
          });
      });
      

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