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

Create a demo script #6

Closed
matthewp opened this issue Feb 22, 2017 · 2 comments
Closed

Create a demo script #6

matthewp opened this issue Feb 22, 2017 · 2 comments

Comments

@matthewp
Copy link
Contributor

matthewp commented Feb 22, 2017

When first starting to work on a library, before you have a good handle on what you are doing it's a good idea to create a demo script that you can work off of. This gives you the ability to look at how the library will be used.

First, update the main module in src/vdom-streaming-serializer.js to look like this:

module.exports = function(element){

};

Then create a demo script in demo/serialize.js that looks like this:

var makeDocument = require('can-vdom/make-document/make-document');
var serialize = require('../src/vdom-streaming-serializer');

var ASYNC = Symbol.for('async-node');

var document = makeDocument();

var h1 = document.createElement('h1');
h1.appendChild(document.createTextNode('Hello world'));
document.body.appendChild(h1);

var ul = document.createElement('ul');
document.body.appendChild(ul);

var li = document.createElement('li');

// Marking this li as async will force the serialize to wait
li[ASYNC] = Promise.resolve();

ul.appendChild(li);

serialize(document.documentElement);

At this point your serialize function doesn't do anything. The next step will be to implement the serializer.

This was referenced Feb 22, 2017
@matthewp
Copy link
Contributor Author

matthewp commented Feb 25, 2017

var child = element.firstChild;
while(child) {
  out += serialize(child);
  child = child.nextSibling;
}

@matthewp
Copy link
Contributor Author

This is done!

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

1 participant