juliangruber / level-list

Map lists of data stored in a LevelDB to DOM elements.
7 stars 1 forks source link

Main example in README not working #13

Closed mtancret closed 6 years ago

mtancret commented 6 years ago

Just ran the main example given in the README and encountered the following error, with nothing displayed in the main window.

bundle.js:4059 Uncaught TypeError: Array.prototype.join called on null or undefined
    at join (native)
    at Stream.<anonymous> (http://localhost:8000/bundle.js:4059:35)
   ...

The error refers to line 31 in index.js. The issue is that the key is assumed to be an array, and this is not the case in the example.

After fixing that issue, a second issue I encountered is that the live stream presents some events the code doesn't deal with. Here is the live stream that I get when running the example.

{key: "1513405217690", value: "[object Object]"}
{sync: true}
{type: "put", key: 1513405217690, value: {…}}
{type: "put", key: 1513405232464, value: {…}}
...

The result is that the list displays undefined a couple of times.

undefined
undefined
Sat Dec 16 2017 00:36:37 GMT-0600 (CST)
Sat Dec 16 2017 00:36:38 GMT-0600 (CST)

I am just learning level, this is the first example I have tried, so I don't know why the live stream works that way. Anyway, here is my solution to fix both issues and get the example code working.

index.js

30   self.stream = live(self.db, function (change) {
31     if (!('key' in change && 'type' in change)) return;
32     
33     var id = Array.isArray(change.key) ?
34       Array.prototype.join.call(change.key, "") : change.key;
35     var row;
36     
37     // delete?

Let me know if you would like a pull request. Thanks for this project, it has really helped introduced me to level.

Matt