WIP: Tree view spec isn't there yet

This commit is contained in:
Nathan Sobo
2012-04-26 09:32:49 -06:00
parent 5c057e11b1
commit 5156a37471
4 changed files with 21 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
Directory = require 'directory'
fs = require 'fs'
fdescribe "Directory", ->
describe "Directory", ->
directory = null
beforeEach ->

View File

@@ -258,17 +258,21 @@ describe "TreeView", ->
beforeEach ->
temporaryFilePath = fs.join(require.resolve('fixtures'), 'temporary')
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
afterEach ->
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
describe "when a file is added or removed in an expanded directory", ->
it "updates the directory view to display the directory's new contents", ->
entriesCountBefore = rootDirectoryView.entries.find('.entry').length
fit "updates the directory view to display the directory's new contents", ->
entriesCountBefore = null
fs.write temporaryFilePath, 'hi'
runs ->
expect(fs.exists(temporaryFilePath)).toBeFalsy()
entriesCountBefore = rootDirectoryView.entries.find('.entry').length
fs.write temporaryFilePath, 'hi'
waitsFor "file to be added", ->
waitsFor "directory view contens to refresh", ->
rootDirectoryView.entries.find('.entry').length == entriesCountBefore + 1
runs ->

View File

@@ -28,24 +28,28 @@ module.exports =
[eventName, namespace] = eventName.split('.')
eventName = undefined if eventName is ''
subscriptionCountBefore = @subscriptionCount()
if namespace
if eventName
handlers = @eventHandlersByNamespace?[namespace]?[eventName] ? []
for handler in new Array(handlers...)
_.remove(handlers, handler)
@off eventName, handler
return
else
for eventName, handlers of @eventHandlersByNamespace?[namespace] ? {}
for handler in new Array(handlers...)
_.remove(handlers, handler)
@off eventName, handler
return
else
if handler
_.remove(@eventHandlersByEventName[eventName], handler)
else
delete @eventHandlersByEventName?[eventName]
@afterUnsubscribe?()
@afterUnsubscribe?() if @subscriptionCount() < subscriptionCountBefore
subscriptionCount: ->
count = 0

View File

@@ -1,6 +1,7 @@
{View, $$} = require 'space-pen'
Directory = require 'directory'
$ = require 'jquery'
_ = require 'underscore'
module.exports =
class TreeView extends View
@@ -85,7 +86,12 @@ class DirectoryView extends View
initialize: ({@directory, isExpanded}) ->
@expand() if isExpanded
@disclosureArrow.on 'click', => @toggleExpansion()
@on 'DOMNodeRemoved', (e) => @unwatchEntries() if e.target == this[0]
_.defer =>
@on 'DOMNodeRemoved', (e) =>
if e.target == this[0] and @hasClass('expanded')
console.log "unwatching!"
@unwatchEntries()
buildEntries: ->
@entries?.remove()