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

on_change if's with nested properties #122

Open
ephopper opened this issue May 24, 2018 · 4 comments
Open

on_change if's with nested properties #122

ephopper opened this issue May 24, 2018 · 4 comments

Comments

@ephopper
Copy link

given a document:

{
	"_id": "foo_doc1",
	"_rev": "1-xxxxxxxxxx",
	"foo": {
		"bar": {
			"baz": true
		}
	}
}

I can create an on_change doc that has:

"if": {
	"_id": "^foo",
	"_deleted": "undefined"
}

these will work fine. However if I try:

"if": {
	"foo": {
		"bar": {
			"baz": true
		}
	}
}

this doesn't seem to work.

are the if's only meant to work against the top-level properties of the documents?

@redgeoff
Copy link
Owner

redgeoff commented May 24, 2018

Yes, the conditional logic only works against the top level. I can think of two possible enhancements for this:

  1. Enhance
    sporks.each(onChange.if, (reStr, name) => {
    to use recursion to support nested properties
  2. Use https://github.com/crcn/sift.js so that we can support a whole host of different matching options. This would be cool, but it would break existing usage of Spiegel as the sift syntax is different than what is currently used in the on_change docs. However, we could prevent breaking existing usage by introducing a new where attribute that uses sift while simulatenously continuing to support the old if attribute.

Interested in implementing either of these?

@ephopper
Copy link
Author

Gotcha. Yeah, I actually found that spot in the code but wasn't sure if I was missing something else.
looking at sift makes me wonder if it wouldn't be possible to use mango selectors in the on_change docs somehow also.
I'm not exactly sure how pouch deals with them off-hand, but I've been using mango selectors in my pouch change listeners and they work fine.
I think for what I'm doing now though, I'll see about filtering the docs in the api called by the on_change doc. If I can find some free time, I'll take a look at what it would take to implement one of your above suggestions.

Thanks!

@redgeoff
Copy link
Owner

Using mango selectors would be a cool idea, but the current design takes a single _changes feed per database and then checks all on_change docs. In order to support mango selectors you'd need a feed per on_change and this would definitely increase the complexity of the change-listeners. I don't think that adding this complexity now is worth the trouble and it could actually lead to a lot of latency.

I still think using sift would be the cleanest enhancement for now.

@ephopper
Copy link
Author

Good point. It seems that avoiding unneeded complexity and latency would be a good idea.

I'll have to keep my work around simple for the now given lack of time, but if I can I'll take a deeper look into sift.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants