CNode

发一个简单的包 Basestone

Iisland205发布于13 年前最后回复13 年前7 回复5778 浏览0 收藏

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)

J
jiyinyiyong#1·13 年前

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

I
island205#2·13 年前
J
jiyinyiyong#3·13 年前
引用 jiyinyiyong没接触过, "数据接口集合"比方说怎么用?

@island205 T_T "数据结构的集合".. 我该复制的..

I
island205#4·13 年前
引用 jiyinyiyong没接触过, "数据接口集合"比方说怎么用?

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

J
jiyinyiyong#5·13 年前
引用 jiyinyiyong没接触过, "数据接口集合"比方说怎么用?

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

I
island205#6·13 年前
引用 jiyinyiyong没接触过, "数据接口集合"比方说怎么用?

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

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

I
irvingzu#7·13 年前

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

参与回复
登录后即可参与回复。登录