Comments (7)
Maybe if .data
is called without any arguments it should reset the data object. Or maybe it would look more clear if the data object could be set by passing .data()
an object instead of a function, then a reset would look like .data({})
or data(null)
. Yet another feature for a future release.
This should work for now:
.then(function(context, data, next) {
next(context, {});
})
from node-osmosis.
In earlier versions of Osmosis .find
would search the entire document. Currently, .find
is relative to the previous context, so .find('aside')
is actually looking in the .find('menu')
. Having .find
be relative to the current context might be slightly better from a performance standpoint, but obviously it's not clear enough that it's relative.
Maybe in the next version .find
will be made to search the entire document and another command will be available for the cases where you specifically want to search in the current context. The question is the right name for the command. I think .child()
would work but it doesn't imply a search.
For right now you can call .doc
to reset the current context:
page = osmosis.get(pageUrl)
.find('menu')
.set({
// get the <menu> links
})
.data(function() {
// do something with the <menu> links
})
.doc()
.find('aside')
.set({
// get the <aside> links
})
.data(function() {
// do something with the <aside> links
})
.then(function() {
// ... finally write everything to disk
});
from node-osmosis.
rc0x03, ah, that's what I was looking for! thank you.
One thing about that example is still a bit odd - when I use .doc() it seems to reset the context and i can find "aside" in a second run, but the 2nd .set().data() seems to merge the response parameter for .data() with the data of the first set. So looks like "data" is passed down the chain. Would there be a way to reset it as well?
eg. if the first call of .set() finds something link
{ link: 'myMenuLink1' }
and the second .set() finds something like { }
{ otherLlink: 'myAsideLink1' }
The parameter of the 2nd .data( function(parameter) {...} ) call looks like this
{
link: 'myMenuLink1',
otherLlink: 'myAsideLink1'
}
I tried to work around this with like this but it didn't seem to have helped:
.set(...)
.data(...)
.then(function(context, data, next) {
delete data;
next(context, data, next);
})
from node-osmosis.
thank you rc0x03 - this works as a workaround.
from node-osmosis.
I'm getting:
.doc() // reset the context
^
TypeError: osmosis.parse(...).find(...).set(...).data(...).doc is not a function
osmosis 1.1.4
Was it removed?
from node-osmosis.
I've got a situation like @achimkoellner, I want to reset the data, so it doesn't accumulate.
from node-osmosis.
@rchipka, I'm successfully using your suggestion.
I think a function officially dedicated to clearing the data would be of great help.
from node-osmosis.
Related Issues (20)
- paginate doesn't preserve the http method
- Cannot get contents of an element that contains < as text HOT 1
- figure and figcaption not supported
- Error: Invalid property for defaults:compressed HOT 8
- A question about osm map quantity
- A question about osm map quantity
- Getting "script" content seems to truncate characters after a limit HOT 2
- Worker_Threads :: Module did not self-register HOT 1
- Get elements that contains only numbers?
- How selector paginate work? HOT 8
- Add support for case insensitive wild card matching
- Build fails on NodeJS 12 HOT 3
- Use with local file HOT 1
- content of xml <link> tag not extracted? HOT 1
- [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated with node 12.16.1
- Get HTML code of element HOT 1
- not working, .data handler not called
- [HOW TO] paginate by click handler, not by link?
- How to scrape the webpage contents which takes some time to load?
- how can return values be guaranteed? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-osmosis.