Atom项目基于许多子项目,这样方便维护与测试。今天来看看pathwatcher(atom/node-pathwatcher)这个项目。
既然nodejs本身提供了监控文件变化的方法,Atom还做了这样一个项目,是为了什么呢?官网的文档等于没有。。。所以还是得自己看。
File类
虽然是pathwatcher项目中的类,但是Atom的其他项目用的也是这个类,比如text-buffer
这个项目,用的就是File类,其中的关键代码如下(text-buffer.coffee
):
{File} = require 'pathwatcher'
# Public: Set the path for the buffer's associated file.
#
# * `filePath` A {String} representing the new file path
setPath: (filePath) ->
return if filePath == @getPath()
if filePath
@file = new File(filePath)
@file.setEncoding(@getEncoding())
@subscribeToFile()
else
@file = null
@emitter.emit 'did-change-path', @getPath()
TODO