Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accumulateChanges supports only a single value per attribute #843

Open
btheado opened this issue Jun 10, 2017 · 4 comments
Open

accumulateChanges supports only a single value per attribute #843

btheado opened this issue Jun 10, 2017 · 4 comments
Assignees

Comments

@btheado
Copy link
Contributor

btheado commented Jun 10, 2017

I'm trying to write a watcher to persist data externally, but I'm getting the error, "accumulateChanges supports only a single value per attribute"

Here is the code (stored in file persist-test.js):

import { Program } from "witheve";

let prog = new Program("persist test");

prog.load(`
~~~
search
  sort = math/range[start: 1 stop: 1]

commit
  [#counter #persist sort count: 0]
~~~
`);

prog.watch("Export #persist tagged data to a tiddler", ({find, record, lookup}) => {
  let rec = find("persist");
  let {attribute, value} = lookup(rec);

  return [
    rec.add(attribute, value)
  ];
})
.asObjects(({adds, removes}) => {
  console.log("obj add  " + JSON.stringify(adds));
  console.log("obj rem  " + JSON.stringify(removes));
});

And I'm running it like this:

node build/src/cli.js -H build/programs/persist-test.js

If I change the watch block to instead look like this:

prog.watch("Export #persist tagged data to a tiddler", ({find, record, lookup}) => {
  let counter = find("counter");
  let {count, sort} = counter;

  return [
    record("counter", {count, sort})
  ];
})

then I don't get the error and I get some reasonable looking output:

obj add  {"tag|counter|count|0|sort|1":{"tag":"counter","sort":1,"count":0}}
obj rem  {}
@joshuafcole
Copy link
Contributor

joshuafcole commented Jun 10, 2017 via email

@btheado
Copy link
Contributor Author

btheado commented Jun 10, 2017

Thanks. I tried asDiffs and it worked fine. I was using asObjects because having the attributes and values for each entity grouped together into a single object was convenient.

I think I can write the code myself to group the array of EAV by entity, but will I run into the same issue which is the reason for your implementation shortcut?

@joshuafcole
Copy link
Contributor

joshuafcole commented Jun 10, 2017 via email

@btheado
Copy link
Contributor Author

btheado commented Jun 11, 2017

Thanks for the tip on treating the attributes as sets. I have used it in my code at https://github.com/btheado/tweve/blob/494ffa1360db9d62c8b67de9a97989eb0217a164/src/plugins/btheado/tweve/eve-widget.js#L78 and it seems to work.

@joshuafcole joshuafcole self-assigned this Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants