-
Notifications
You must be signed in to change notification settings - Fork 120
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
Custom elements support in domino #96
Open
majo44
wants to merge
12
commits into
fgnass:master
Choose a base branch
from
majo44:custom-elements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0aec8b1
custom-elements support implementation
e9c9cee
custom-elements support implementation
0ea41bc
lint fixes
0e93820
fix breaking changes
70c9b2a
fix breaking changes
71f6cb7
fix breaking changes,
df411c4
lint :(
fbf0cfd
normalize paths
3d8e761
enabling all platform tests
acc3848
enabling all platform tests
db79925
fix for case where observableAttributes is just getter
cffd4cf
enabling all platform tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
"use strict"; | ||
var xml = require('./xmlnames'); | ||
|
||
var forbiddenNames = [ | ||
'annotation-xml', | ||
'color-profile', | ||
'font-face', | ||
'font-face-src', | ||
'font-face-uri', | ||
'font-face-format', | ||
'font-face-name', | ||
'missing-glyph']; | ||
|
||
var forbiddenExtendsNames = [ | ||
'bgsound', | ||
'blink', | ||
'isindex', | ||
'multicol', | ||
'nextid', | ||
'spacer', | ||
'elementnametobeunknownelement' | ||
]; | ||
|
||
function isInvalidCustomElementName(name) { | ||
return !name || !xml.isValidQName(name) || name.indexOf('-') < 0 || forbiddenNames.indexOf(name) > -1 || name.toLowerCase() !== name; | ||
} | ||
|
||
function CustomElementRegistry(registry, document) { | ||
this._parent = registry; | ||
this._document = document; | ||
this._registry = {}; | ||
this._clonesRegistry = {}; | ||
this._options = {}; | ||
this._promises = {}; | ||
} | ||
|
||
/** | ||
* @param {string} name | ||
* @param {Function} constructor | ||
* @param options | ||
*/ | ||
CustomElementRegistry.prototype.define = function(name, constructor, options) { | ||
var err; | ||
if (!constructor) { | ||
err = new TypeError('Provide name and constructor'); | ||
throw err; | ||
} | ||
|
||
if (!constructor) throw new TypeError('Provide constructor'); | ||
if (typeof constructor !== 'function') throw new TypeError('Constructor have to be a function'); | ||
if (!constructor.prototype) throw new TypeError('Constructor'); | ||
if (typeof constructor.prototype === 'string') throw new TypeError('Constructor prototype is string'); | ||
|
||
if (isInvalidCustomElementName(name)) { | ||
err = new SyntaxError('Invalid name'); | ||
err.code = 12; | ||
throw err; | ||
} | ||
|
||
if (this._registry[name]) { | ||
err = new Error('Name already used'); | ||
err.name = 'NOT_SUPPORTED_ERR'; | ||
err.code = 9; | ||
throw err; | ||
} | ||
|
||
var _registry = this._registry; | ||
Object.keys(this._registry).forEach(function(_name) { | ||
if (constructor === _registry[_name]) { | ||
err = new Error('Constructor already used'); | ||
err.name = 'NOT_SUPPORTED_ERR'; | ||
err.code = 9; | ||
throw err; | ||
} | ||
}); | ||
|
||
if (options && options.extends && (!isInvalidCustomElementName(options.extends) || forbiddenExtendsNames.indexOf(options.extends > -1))) { | ||
err = new Error('Extend have to be build in type'); | ||
err.name = 'NOT_SUPPORTED_ERR'; | ||
err.code = 9; | ||
throw err; | ||
} | ||
|
||
['connectedCallback', | ||
'disconnectedCallback', | ||
'adoptedCallback', | ||
'attributeChangedCallback'].forEach(function(prop) { | ||
var type = typeof constructor.prototype[prop]; | ||
if (type !== 'undefined' && type !== 'function') { | ||
throw new TypeError(name + ' have to be function'); | ||
} | ||
}); | ||
|
||
this._registry[name] = constructor; | ||
|
||
|
||
// we have to clone class to fallow the spec (after define observedAttributes and attributeChangedCallback mutation | ||
// do not have effect) | ||
this._clonesRegistry[name] = class extends constructor {}; | ||
|
||
if (constructor.observedAttributes) { | ||
let observedAttributes; | ||
if (Array.isArray(constructor.observedAttributes)) { | ||
observedAttributes = constructor.observedAttributes.slice(); | ||
} else if (constructor.observedAttributes && constructor.observedAttributes[Symbol.iterator]) { | ||
observedAttributes = Array.from(constructor.observedAttributes[Symbol.iterator]()); | ||
} | ||
Object.defineProperty(this._clonesRegistry[name], 'observedAttributes', { | ||
get: function() { | ||
return observedAttributes; | ||
} | ||
}); | ||
} | ||
|
||
this._clonesRegistry[name].prototype.attributeChangedCallback = constructor.prototype.attributeChangedCallback; | ||
this._clonesRegistry[name].prototype.connectedCallback = constructor.prototype.connectedCallback; | ||
this._clonesRegistry[name].prototype.disconnectedCallback = constructor.prototype.disconnectedCallback; | ||
|
||
this._options[name] = options; | ||
if (this._promises[name]) { | ||
this._promises[name].resolve(); | ||
} | ||
|
||
if (this._document) { | ||
// TODO apply new item to existing content | ||
} | ||
|
||
}; | ||
|
||
CustomElementRegistry.prototype.get = function(name) { | ||
if (this._clonesRegistry[name]) { | ||
return this._clonesRegistry[name]; | ||
} else if (this._parent) { | ||
return this._parent.get(name); | ||
} | ||
}; | ||
|
||
CustomElementRegistry.prototype.whenDefined = function(name) { | ||
if (this._promises[name]) { | ||
return this._promises[name]; | ||
} else if (this._registry[name]) { | ||
return Promise.resolve(); | ||
} else { | ||
var resolve; | ||
var promise = new Promise(function (res){ | ||
resolve = res; | ||
}); | ||
promise.resolve = resolve; | ||
this._promises[name] = promise; | ||
return promise; | ||
|
||
} | ||
}; | ||
|
||
module.exports = CustomElementRegistry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use strict"; | ||
module.exports.preventNotify = false; | ||
|
||
module.exports.notifyCustomElementsSetAttrCallback = function(node, name, oldValue, newValue, ns) { | ||
if (node.constructor.observedAttributes && node.constructor.observedAttributes.indexOf(name) > -1) { | ||
if (node.attributeChangedCallback) { | ||
if (oldValue === undefined) oldValue = null; | ||
if (newValue === undefined) newValue = null; | ||
node.attributeChangedCallback(name, oldValue, newValue, ns || null); | ||
} | ||
} | ||
}; | ||
|
||
module.exports.notifyCloned = function(n) { | ||
//nyi(); | ||
}; | ||
|
||
module.exports.notifyRooted = function(n) { | ||
if (!exports.preventNotify) { | ||
// CEv1 | ||
if (n.adoptedCallback && n._lastDocument && (n._lastDocument !== n.ownerDocument)) { | ||
n.adoptedCallback(n._lastDocument, n.ownerDocument); | ||
delete n._lastDocument; | ||
} | ||
// CEv1 | ||
if (n.connectedCallback) { | ||
n.connectedCallback(); | ||
} | ||
} | ||
}; | ||
|
||
module.exports.notifyUpRooted = function(n) { | ||
if (!exports.preventNotify) { | ||
// CEv1 | ||
if (n.adoptedCallback) { | ||
n._lastDocument = n.ownerDocument; | ||
} | ||
// CEv1 | ||
if (n.disconnectedCallback) { | ||
n.disconnectedCallback(); | ||
} | ||
} | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am totally new to domino, but shouldn't you just use
Class
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also new :) but as I see domino should work with node 0.8 so in code the class syntax is not used, unfortunately, I had to use class syntax in one place and I do not know how to avoid it :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't noticed anything regarding this at package.json or in the readme.
@fgnass
Though it makes sense to have engine key in package json. Semantic increment of version shouldn't hurt anyone since Classes supported from 4th version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rootical
Please look at travis :(