MySelectListView example is broken


#1

The example here https://atom.io/docs/api/v0.60.0/api/classes/SelectListView.html always calls cancel. I went as far as determining SelectListView.prototype.populateList is called (sets data) but the nodes don’t have any data on the other side. I would try to pin this down, but the debugger itself is broken. Its possible this is just an error in use, but I don’t have an example of proper usage.


#2

I found a solution (use the dsl ) (utils stuff is below):

var util = require('util'),
  utils = require('./utils'),
  _ = require('lodash'),
  $$ = require('atom').$$,
  SelectListView = require("atom").SelectListView;

var RecentWorkspaceView = function(){
  SelectListView.apply(this, arguments);
};

utils.inherits(RecentWorkspaceView, SelectListView);

RecentWorkspaceView.prototype.initialize = function() {
  var self = this;
  SelectListView.prototype.initialize.apply(self, arguments);
  
  self.addClass('overlay from-top');
  self.setItems(['Hello', 'World']);
  atom.workspaceView.append(this);
  self.focusFilterEditor();
};

RecentWorkspaceView.prototype.viewForItem = function(item) {
  // return "<li><div>" + item + "</div></li>";
  return $$(function() {
    var self = this;
    this.li(function() {
      self.div(item);
    });
  });
};

RecentWorkspaceView.prototype.confirmed = function(item) {
  console.log(util.format("%s was selected", item));
  this.cancel();
};

RecentWorkspaceView.prototype.cancelled = function() {
  console.log("cancelled");
};

exports.RecentWorkspaceView = RecentWorkspaceView;

utils:

var __hasProp = {}.hasOwnProperty;
var inherits = function(child, parent) { 
  // from CS :(
  for (var key in parent) { 
    if (__hasProp.call(parent, key)) child[key] = parent[key]; 
  } 
  function ctor() { this.constructor = child; } 
  ctor.prototype = parent.prototype; 
  child.prototype = new ctor(); 
  child.__super__ = parent.prototype; 
  return child; 
};