发一个简单的包 Basestone
发布于 11 年前 作者 island205 4666 次浏览 最后一次编辑是 8 年前

Basestone的目标是做一个JavaScript数据结构的集合,且这写数据结构应该足够smart。 一个combine文件的例子:

var filesToRead, fs, basestone;
fs = require('fs');
basestone = require('basestone');
filesToRead = basestone.map([
    ['./google.js', ''],
    ['./baidu.js', ''],
    ['./douban.js', '']
]);
filesToRead.on('change', function (key, value) {
    var filesData, isAllReaded;
    console.log(key + ' is readed')
    filesData = this.values();
    isAllReaded = filesData.every(function (data) {
        return data !== '';
    });
    if (isAllReaded) {
        console.log('all files are readed and combined:\n')
        console.log(filesData.join('\n'));
    }
});
filesToRead.keys(function (fileName) {
    fs.readFile(fileName, function (err, data) {
        if (!err) {
            filesToRead.set(fileName, data);
        }
    });
});

可以说是attr的一个扩展,还有点像Backbone的model和collection。 现在还比较粗糙,wrapper也不够高效。 大家帮忙看看,文档在这里

7 回复

没接触过, "数据接口集合"比方说怎么用?

god,写错了,是数据结构。

@island205 T_T “数据结构的集合”… 我该复制的…

@jiyinyiyong 我修改过了,你确实是复制到。

@island205 哦… 能不能介绍下用例? 还是不太明白

@jiyinyiyong 上面的这个例子就是异步地读取google.jsbaidu.jsdouban.js这三个文件,当都读取好了之后,打包输出。

这个场景如果使用async.js写起来会更简单。

您好,DeNA在招聘资深node.js的职位,您有兴趣考虑吗?

回到顶部