Slight improvements to ID generation and other cleanup

This commit is contained in:
Patrick Steele-Idem 2017-02-25 19:56:20 -07:00
parent 8adf6bd92e
commit 8277b83566
10 changed files with 21 additions and 45 deletions

View File

@ -95,7 +95,7 @@ ComponentDef.prototype = {
var id = this.id;
return id ?
id + '-w' + (this.$__nextIdIndex++) :
id + '-c' + (this.$__nextIdIndex++) :
nextComponentId(this.$__out);
},

View File

@ -7,7 +7,7 @@ var ComponentsContext = require('./ComponentsContext');
var registry = require('./registry');
var extend = require('raptor-util/extend');
var WIDGETS_BEGIN_ASYNC_ADDED_KEY = '$wa';
var COMPONENT_BEGIN_ASYNC_ADDED_KEY = '$wa';
function resolveComponentKey(out, key, scope) {
if (key.charAt(0) == '#') {
@ -83,8 +83,8 @@ function createRendererFunc(templateRenderFunc, componentProps, renderingLogic)
var outGlobal = out.global;
if (!out.isSync()) {
if (!outGlobal[WIDGETS_BEGIN_ASYNC_ADDED_KEY]) {
outGlobal[WIDGETS_BEGIN_ASYNC_ADDED_KEY] = true;
if (!outGlobal[COMPONENT_BEGIN_ASYNC_ADDED_KEY]) {
outGlobal[COMPONENT_BEGIN_ASYNC_ADDED_KEY] = true;
out.on('beginAsync', handleBeginAsync);
}
}

View File

@ -92,7 +92,7 @@ function nextComponentId() {
// marko runtimes. This allows multiple instances of marko to be
// loaded in the same window and they should all place nice
// together
return 'c' + ((markoGlobal.uid)++);
return 'b' + ((markoGlobal.uid)++);
}
function getElementById(doc, id) {

View File

@ -2,7 +2,7 @@ var KEY = Symbol();
var isArray = Array.isArray;
function UniqueId(out) {
this.prefix = out.global.componentIdPrefix || 's'; // "s" is for server (we use "c" for the client/browser)
this.prefix = out.global.componentIdPrefix || 's'; // "s" is for server (we use "b" for the browser)
this.nextId = 0;
}

View File

@ -1,26 +0,0 @@
module.exports = require('marko/components/legacy').defineComponent({
template: require.resolve('./template.marko'),
getComponentConfig: function() {
return {
type: 'component config'
};
},
getInitialState: function() {
return {
type: 'component state'
};
},
getTemplateData: function(state, input) {
return {
name: input.name,
messageCount: input.messageCount
};
},
init: function(componentConfig) {
this.componentConfig = componentConfig;
}
});

View File

@ -1,4 +1,8 @@
<div w-bind>
class {
}
<div>
Hello ${data.name}! You have ${data.messageCount} new messages.
<div key="foo">foo</div>
</div>

View File

@ -1,4 +1,8 @@
<div w-bind>
class {
}
<div>
<app-simple name="Frank" count=20/>
<app-simple name="John" count=30/>
</div>

View File

@ -1,3 +0,0 @@
{
"tags-dir": "./components"
}

View File

@ -2,18 +2,20 @@ var expect = require('chai').expect;
var markoComponents = require('marko/components');
module.exports = function(helpers, done) {
var template = require('./template.marko');
var template = require('./index.marko');
template.renderToString({}, function(err, html, out) {
var renderedComponents = markoComponents.getRenderedComponents(out);
expect(renderedComponents).to.be.an('object');
console.log('HTML', html);
expect(Object.keys(renderedComponents).length).to.equal(2);
var componentDefs = renderedComponents.w;
expect(componentDefs.length).to.equal(3);
expect(componentDefs[0][0]).to.equal('s0-w0');
expect(componentDefs[1][0]).to.equal('s0-w1');
expect(componentDefs[0][0]).to.equal('s0-c0');
expect(componentDefs[1][0]).to.equal('s0-c1');
expect(componentDefs[2][0]).to.equal('s0');
done();
});

View File

@ -1,5 +0,0 @@
function Component() {
}
module.exports = Component;