Giter Site home page Giter Site logo

Comments (7)

rchipka avatar rchipka commented on September 25, 2024 2

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.

rchipka avatar rchipka commented on September 25, 2024

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.

achimkoellner avatar achimkoellner commented on September 25, 2024

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.

achimkoellner avatar achimkoellner commented on September 25, 2024

thank you rc0x03 - this works as a workaround.

from node-osmosis.

specious avatar specious commented on September 25, 2024

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.

specious avatar specious commented on September 25, 2024

I've got a situation like @achimkoellner, I want to reset the data, so it doesn't accumulate.

from node-osmosis.

specious avatar specious commented on September 25, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.