Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Text Editor - Start">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>CanJS</title>
</head>
<body>
<script src="https://unpkg.com/can@3.0/dist/global/can.js"></script>
</body>
</html>
 
ViewModel = can.DefineMap.extend({
  get myPromise() {
    return new Promise(function(resolve ){
      setTimeout(function(){
        resolve(new can.DefineList([
          {id: 1, name: "zoo"},
          {id: 2, name: "apple"}
        ]))
      },1000)
    });
  },
  elements: {
    get: function(last, set) {
      this.myPromise.then(set);
    }
  },
  modifiedElements: {
    get: function() {
      if (this.elements !== undefined) {
        var res = this.elements.get().sort(function(a,b){
          return -1;
        });
        return res;
      }
    }
  },
});
var view = can.stache(`<ul>
  {{#each modifiedElements}}
    <li>{{name}}</li>
  {{/each}}
  </ul>`)
document.body.appendChild( view(new ViewModel()) );
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
justinbmeyerpro
0viewers