juliangruber / juliangruber/level-list
Problems mixing EventEmitter and data
- Dominant language
- HTML
- Stars
- 7
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
By adding data properties straight to the EventEmitter there is no way to sanely serialize the object.
## My Scenario
I'm creating an input based on a certain key, it will alter value and attempt to save the data. The problem that currently occurs is the json-serialization barfs (max call stack) trying to serialize the EventEmitter.
Code loosely looks like this.
```
List(db, function(row) {
var el = document.createElement("div");
var check = document.createElement("input");
check.type = "checkbox";
check.checked = row.active || false;
check.addEventListener("change", function() {
row.active = check.checked;
db.put(row.id, row); // <---- cannot serialize
});
return el;
});
```
My suggestion would be keeping more closely aligned with level and store actually data on the `EventEmitter` under the `.value` key.
```
List(db, function(row) {
row.on("update active", function() {
console.log("active state changed to %s", row.value.active);
// .... blah blah, do stuff
db.put(row._key, row.value);
});
});
```
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue names EventEmitter, DOM inputs, and db.put but no repository files or tests. Start by locating where list rows are constructed and how their data is attached, then trace the serialization path shown in the example. Done means the proposed data-access shape is agreed and serializing a row for db.put no longer traverses the EventEmitter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- database, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100