You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means our serialize function needs to return a stream. The type of stream we will create is a Readable stream.
Make the module return a stream
Update src/vdom-streaming-serializer.js to look like this:
varReadable=require('stream').Readable;module.exports=function(element){varstream=newReadable();stream._read=function(){// This is where we start doing stuff};returnstream;};
This makes our module implement the API it is supposed to... it just doesn't do anything yet. We'll do that later.
varstream=serialize(document.documentElement);stream.on('data',function(chunk){// This is a chunk of HTML!console.log(chunk);});stream.on('end',function(){// All HTML has been written});
Now you've created a stream, it just never fires events. The next step is to do the hard work of implementing the streaming serializer.
Making the serializer work
Keys here are:
We want to create HTML strings so we need:
The tag name (element.localName)
Its attributes (which you can loop over with element.attributes)
Its children (which you can loop over with element.childNodes)
When you come to a Node (either an attribute, element, or text) that is marked as Symbol.for('async-node') you need to stop.
Flush the current html string parts when you hit an async node.
When the async node results, continue where you left off.
The async node might have been replaced, so keep a reference to the parent and the position that your node sits.
The text was updated successfully, but these errors were encountered:
Referring to the API issue you can see that the serializer module should be used like so:
This means our serialize function needs to return a stream. The type of stream we will create is a Readable stream.
Make the module return a stream
Update
src/vdom-streaming-serializer.js
to look like this:This makes our module implement the API it is supposed to... it just doesn't do anything yet. We'll do that later.
Update the demo script
Back in the demo script you created earlier, update it to read from the stream:
Now you've created a stream, it just never fires events. The next step is to do the hard work of implementing the streaming serializer.
Making the serializer work
Keys here are:
element.localName
)element.attributes
)element.childNodes
)Symbol.for('async-node')
you need to stop.The text was updated successfully, but these errors were encountered: