DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
      • computeSettings
      • compute
    • can-connect
    • 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-compute
  • /
  • async
  • / On this page
    • async

      function

      Create a compute that can set its value after the computed function has been called.

      • source

      compute.async(initialValue, computed(currentValue, setValue(newValue) )

      Parameters

      1. The {*}:

        initial value of the compute.

      2. computed {asyncComputer(lastSetValue, setVal)}:

        A function that returns the current value of the compute and can optionally later call its setValue callback to update the value.

      Returns

      {compute(newVal)}:

      Returns a compute, but a compute that will possibly not have the correct value unless it is bound to.

      Use

      The following compute is a live list of todos for a given userId. todos value would alternate between null and a Todo.List as userId changes.

      var userId = compute(5)
      
      var todos = compute.async(null, function(oldTodoList, setValue){
        Todo.findAll({ userId: userId() }, function(todos){
          setValue(todos)
        });
        return null;
      });
      

      The following replaces the list in place:

      var userId = compute(5)
      
      var todos = compute.async(new Todo.List(), function(todoList, setValue){
        todoList.replace( Todo.findAll({ userId: userId() })
        return todoList;
      });
      

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