Add editorconfig, resolve differences
This includes newlines, tabs, among other things.
This commit is contained in:
parent
80d0a69dab
commit
b4fb21475c
90 changed files with 1707 additions and 1701 deletions
10
.editorconfig
Normal file
10
.editorconfig
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
|
||||
[*.js]
|
||||
indent_style = tab
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
510
.eslintrc.js
510
.eslintrc.js
|
|
@ -1,257 +1,257 @@
|
|||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"commonjs": true,
|
||||
"node": true
|
||||
},
|
||||
"globals": {
|
||||
"Promise": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"accessor-pairs": "error",
|
||||
"array-bracket-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"array-callback-return": "error",
|
||||
"arrow-body-style": "error",
|
||||
"arrow-parens": "error",
|
||||
"arrow-spacing": "error",
|
||||
"block-scoped-var": "off",
|
||||
"block-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"brace-style": "off",
|
||||
"callback-return": "off",
|
||||
"camelcase": "error",
|
||||
"comma-dangle": "off",
|
||||
"comma-spacing": [
|
||||
"error",
|
||||
{
|
||||
"after": true,
|
||||
"before": false
|
||||
}
|
||||
],
|
||||
"comma-style": [
|
||||
"error",
|
||||
"last"
|
||||
],
|
||||
"complexity": "off",
|
||||
"computed-property-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"consistent-return": "off",
|
||||
"consistent-this": "off",
|
||||
"curly": "off",
|
||||
"default-case": "off",
|
||||
"dot-location": [
|
||||
"error",
|
||||
"property"
|
||||
],
|
||||
"dot-notation": "off",
|
||||
"eol-last": "off",
|
||||
"eqeqeq": "off",
|
||||
"func-names": "off",
|
||||
"func-style": "off",
|
||||
"generator-star-spacing": "error",
|
||||
"global-require": "error",
|
||||
"guard-for-in": "off",
|
||||
"handle-callback-err": "error",
|
||||
"id-blacklist": "error",
|
||||
"id-length": "off",
|
||||
"id-match": "error",
|
||||
"indent": "off",
|
||||
"init-declarations": "off",
|
||||
"jsx-quotes": "error",
|
||||
"key-spacing": "error",
|
||||
"keyword-spacing": [
|
||||
"error",
|
||||
{
|
||||
"before": true,
|
||||
"after": true
|
||||
}
|
||||
],
|
||||
"lines-around-comment": "error",
|
||||
"max-depth": "off",
|
||||
"max-len": "off",
|
||||
"max-nested-callbacks": "error",
|
||||
"max-params": "off",
|
||||
"max-statements": "off",
|
||||
"max-statements-per-line": "off",
|
||||
"new-parens": "off",
|
||||
"newline-after-var": "off",
|
||||
"newline-before-return": "off",
|
||||
"newline-per-chained-call": "off",
|
||||
"no-alert": "error",
|
||||
"no-array-constructor": "error",
|
||||
"no-bitwise": "off",
|
||||
"no-caller": "error",
|
||||
"no-catch-shadow": "error",
|
||||
"no-cond-assign": "off",
|
||||
"no-confusing-arrow": "error",
|
||||
"no-continue": "error",
|
||||
"no-div-regex": "error",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-else-return": "off",
|
||||
"no-empty-function": "off",
|
||||
"no-eq-null": "off",
|
||||
"no-eval": "error",
|
||||
"no-extend-native": "error",
|
||||
"no-extra-bind": "error",
|
||||
"no-extra-label": "error",
|
||||
"no-extra-parens": "off",
|
||||
"no-floating-decimal": "error",
|
||||
"no-implicit-coercion": "error",
|
||||
"no-implicit-globals": "error",
|
||||
"no-implied-eval": "error",
|
||||
"no-inline-comments": "off",
|
||||
"no-inner-declarations": [
|
||||
"error",
|
||||
"functions"
|
||||
],
|
||||
"no-invalid-this": "off",
|
||||
"no-iterator": "error",
|
||||
"no-label-var": "error",
|
||||
"no-labels": "error",
|
||||
"no-lone-blocks": "error",
|
||||
"no-lonely-if": "off",
|
||||
"no-loop-func": "off",
|
||||
"no-magic-numbers": "off",
|
||||
"no-mixed-requires": "error",
|
||||
"no-multi-spaces": "error",
|
||||
"no-multi-str": "error",
|
||||
"no-multiple-empty-lines": "error",
|
||||
"no-native-reassign": "error",
|
||||
"no-negated-condition": "off",
|
||||
"no-nested-ternary": "off",
|
||||
"no-new": "off",
|
||||
"no-new-func": "off",
|
||||
"no-new-object": "error",
|
||||
"no-new-require": "error",
|
||||
"no-new-wrappers": "error",
|
||||
"no-octal-escape": "error",
|
||||
"no-param-reassign": "off",
|
||||
"no-path-concat": "error",
|
||||
"no-plusplus": "off",
|
||||
"no-process-env": "error",
|
||||
"no-process-exit": "error",
|
||||
"no-proto": "error",
|
||||
"no-redeclare": "off",
|
||||
"no-restricted-globals": "error",
|
||||
"no-restricted-imports": "error",
|
||||
"no-restricted-modules": "error",
|
||||
"no-restricted-syntax": "error",
|
||||
"no-return-assign": "off",
|
||||
"no-script-url": "error",
|
||||
"no-self-compare": "error",
|
||||
"no-sequences": "off",
|
||||
"no-shadow": "off",
|
||||
"no-shadow-restricted-names": "error",
|
||||
"no-spaced-func": "error",
|
||||
"no-sync": "off",
|
||||
"no-ternary": "off",
|
||||
"no-throw-literal": "error",
|
||||
"no-trailing-spaces": [
|
||||
"error",
|
||||
{
|
||||
"skipBlankLines": true
|
||||
}
|
||||
],
|
||||
"no-undef-init": "error",
|
||||
"no-undefined": "off",
|
||||
"no-underscore-dangle": "error",
|
||||
"no-unmodified-loop-condition": "error",
|
||||
"no-unneeded-ternary": "error",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unused-expressions": "off",
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"varsIgnorePattern": "module"
|
||||
}
|
||||
],
|
||||
"no-use-before-define": "off",
|
||||
"no-useless-call": "error",
|
||||
"no-useless-computed-key": "error",
|
||||
"no-useless-concat": "error",
|
||||
"no-useless-constructor": "error",
|
||||
"no-useless-escape": "off",
|
||||
"no-var": "off",
|
||||
"no-void": "error",
|
||||
"no-warning-comments": "off",
|
||||
"no-whitespace-before-property": "error",
|
||||
"no-with": "error",
|
||||
"object-curly-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"object-property-newline": [
|
||||
"error",
|
||||
{
|
||||
"allowMultiplePropertiesPerLine": true
|
||||
}
|
||||
],
|
||||
"object-shorthand": "off",
|
||||
"one-var": "off",
|
||||
"one-var-declaration-per-line": "off",
|
||||
"operator-assignment": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"operator-linebreak": [
|
||||
"error",
|
||||
"after"
|
||||
],
|
||||
"padded-blocks": "off",
|
||||
"prefer-arrow-callback": "off",
|
||||
"prefer-const": "error",
|
||||
"prefer-reflect": "off",
|
||||
"prefer-rest-params": "off",
|
||||
"prefer-spread": "off",
|
||||
"prefer-template": "off",
|
||||
"quote-props": "off",
|
||||
"quotes": [
|
||||
"error",
|
||||
"double"
|
||||
],
|
||||
"radix": [
|
||||
"error",
|
||||
"as-needed"
|
||||
],
|
||||
"require-jsdoc": "off",
|
||||
"require-yield": "error",
|
||||
"semi": "off",
|
||||
"semi-spacing": [
|
||||
"error",
|
||||
{
|
||||
"after": true,
|
||||
"before": false
|
||||
}
|
||||
],
|
||||
"sort-imports": "error",
|
||||
"sort-vars": "off",
|
||||
"space-before-blocks": "error",
|
||||
"space-before-function-paren": "off",
|
||||
"space-in-parens": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"space-infix-ops": "error",
|
||||
"space-unary-ops": "off",
|
||||
"spaced-comment": "off",
|
||||
"strict": "off",
|
||||
"template-curly-spacing": "error",
|
||||
"valid-jsdoc": "error",
|
||||
"vars-on-top": "off",
|
||||
"wrap-iife": "error",
|
||||
"wrap-regex": "error",
|
||||
"yield-star-spacing": "error",
|
||||
"yoda": [
|
||||
"error",
|
||||
"never"
|
||||
]
|
||||
}
|
||||
"env": {
|
||||
"browser": true,
|
||||
"commonjs": true,
|
||||
"node": true
|
||||
},
|
||||
"globals": {
|
||||
"Promise": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"accessor-pairs": "error",
|
||||
"array-bracket-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"array-callback-return": "error",
|
||||
"arrow-body-style": "error",
|
||||
"arrow-parens": "error",
|
||||
"arrow-spacing": "error",
|
||||
"block-scoped-var": "off",
|
||||
"block-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"brace-style": "off",
|
||||
"callback-return": "off",
|
||||
"camelcase": "error",
|
||||
"comma-dangle": "off",
|
||||
"comma-spacing": [
|
||||
"error",
|
||||
{
|
||||
"after": true,
|
||||
"before": false
|
||||
}
|
||||
],
|
||||
"comma-style": [
|
||||
"error",
|
||||
"last"
|
||||
],
|
||||
"complexity": "off",
|
||||
"computed-property-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"consistent-return": "off",
|
||||
"consistent-this": "off",
|
||||
"curly": "off",
|
||||
"default-case": "off",
|
||||
"dot-location": [
|
||||
"error",
|
||||
"property"
|
||||
],
|
||||
"dot-notation": "off",
|
||||
"eol-last": "off",
|
||||
"eqeqeq": "off",
|
||||
"func-names": "off",
|
||||
"func-style": "off",
|
||||
"generator-star-spacing": "error",
|
||||
"global-require": "error",
|
||||
"guard-for-in": "off",
|
||||
"handle-callback-err": "error",
|
||||
"id-blacklist": "error",
|
||||
"id-length": "off",
|
||||
"id-match": "error",
|
||||
"indent": "off",
|
||||
"init-declarations": "off",
|
||||
"jsx-quotes": "error",
|
||||
"key-spacing": "error",
|
||||
"keyword-spacing": [
|
||||
"error",
|
||||
{
|
||||
"before": true,
|
||||
"after": true
|
||||
}
|
||||
],
|
||||
"lines-around-comment": "error",
|
||||
"max-depth": "off",
|
||||
"max-len": "off",
|
||||
"max-nested-callbacks": "error",
|
||||
"max-params": "off",
|
||||
"max-statements": "off",
|
||||
"max-statements-per-line": "off",
|
||||
"new-parens": "off",
|
||||
"newline-after-var": "off",
|
||||
"newline-before-return": "off",
|
||||
"newline-per-chained-call": "off",
|
||||
"no-alert": "error",
|
||||
"no-array-constructor": "error",
|
||||
"no-bitwise": "off",
|
||||
"no-caller": "error",
|
||||
"no-catch-shadow": "error",
|
||||
"no-cond-assign": "off",
|
||||
"no-confusing-arrow": "error",
|
||||
"no-continue": "error",
|
||||
"no-div-regex": "error",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-else-return": "off",
|
||||
"no-empty-function": "off",
|
||||
"no-eq-null": "off",
|
||||
"no-eval": "error",
|
||||
"no-extend-native": "error",
|
||||
"no-extra-bind": "error",
|
||||
"no-extra-label": "error",
|
||||
"no-extra-parens": "off",
|
||||
"no-floating-decimal": "error",
|
||||
"no-implicit-coercion": "error",
|
||||
"no-implicit-globals": "error",
|
||||
"no-implied-eval": "error",
|
||||
"no-inline-comments": "off",
|
||||
"no-inner-declarations": [
|
||||
"error",
|
||||
"functions"
|
||||
],
|
||||
"no-invalid-this": "off",
|
||||
"no-iterator": "error",
|
||||
"no-label-var": "error",
|
||||
"no-labels": "error",
|
||||
"no-lone-blocks": "error",
|
||||
"no-lonely-if": "off",
|
||||
"no-loop-func": "off",
|
||||
"no-magic-numbers": "off",
|
||||
"no-mixed-requires": "error",
|
||||
"no-multi-spaces": "error",
|
||||
"no-multi-str": "error",
|
||||
"no-multiple-empty-lines": "error",
|
||||
"no-native-reassign": "error",
|
||||
"no-negated-condition": "off",
|
||||
"no-nested-ternary": "off",
|
||||
"no-new": "off",
|
||||
"no-new-func": "off",
|
||||
"no-new-object": "error",
|
||||
"no-new-require": "error",
|
||||
"no-new-wrappers": "error",
|
||||
"no-octal-escape": "error",
|
||||
"no-param-reassign": "off",
|
||||
"no-path-concat": "error",
|
||||
"no-plusplus": "off",
|
||||
"no-process-env": "error",
|
||||
"no-process-exit": "error",
|
||||
"no-proto": "error",
|
||||
"no-redeclare": "off",
|
||||
"no-restricted-globals": "error",
|
||||
"no-restricted-imports": "error",
|
||||
"no-restricted-modules": "error",
|
||||
"no-restricted-syntax": "error",
|
||||
"no-return-assign": "off",
|
||||
"no-script-url": "error",
|
||||
"no-self-compare": "error",
|
||||
"no-sequences": "off",
|
||||
"no-shadow": "off",
|
||||
"no-shadow-restricted-names": "error",
|
||||
"no-spaced-func": "error",
|
||||
"no-sync": "off",
|
||||
"no-ternary": "off",
|
||||
"no-throw-literal": "error",
|
||||
"no-trailing-spaces": [
|
||||
"error",
|
||||
{
|
||||
"skipBlankLines": true
|
||||
}
|
||||
],
|
||||
"no-undef-init": "error",
|
||||
"no-undefined": "off",
|
||||
"no-underscore-dangle": "error",
|
||||
"no-unmodified-loop-condition": "error",
|
||||
"no-unneeded-ternary": "error",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unused-expressions": "off",
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"varsIgnorePattern": "module"
|
||||
}
|
||||
],
|
||||
"no-use-before-define": "off",
|
||||
"no-useless-call": "error",
|
||||
"no-useless-computed-key": "error",
|
||||
"no-useless-concat": "error",
|
||||
"no-useless-constructor": "error",
|
||||
"no-useless-escape": "off",
|
||||
"no-var": "off",
|
||||
"no-void": "error",
|
||||
"no-warning-comments": "off",
|
||||
"no-whitespace-before-property": "error",
|
||||
"no-with": "error",
|
||||
"object-curly-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"object-property-newline": [
|
||||
"error",
|
||||
{
|
||||
"allowMultiplePropertiesPerLine": true
|
||||
}
|
||||
],
|
||||
"object-shorthand": "off",
|
||||
"one-var": "off",
|
||||
"one-var-declaration-per-line": "off",
|
||||
"operator-assignment": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"operator-linebreak": [
|
||||
"error",
|
||||
"after"
|
||||
],
|
||||
"padded-blocks": "off",
|
||||
"prefer-arrow-callback": "off",
|
||||
"prefer-const": "error",
|
||||
"prefer-reflect": "off",
|
||||
"prefer-rest-params": "off",
|
||||
"prefer-spread": "off",
|
||||
"prefer-template": "off",
|
||||
"quote-props": "off",
|
||||
"quotes": [
|
||||
"error",
|
||||
"double"
|
||||
],
|
||||
"radix": [
|
||||
"error",
|
||||
"as-needed"
|
||||
],
|
||||
"require-jsdoc": "off",
|
||||
"require-yield": "error",
|
||||
"semi": "off",
|
||||
"semi-spacing": [
|
||||
"error",
|
||||
{
|
||||
"after": true,
|
||||
"before": false
|
||||
}
|
||||
],
|
||||
"sort-imports": "error",
|
||||
"sort-vars": "off",
|
||||
"space-before-blocks": "error",
|
||||
"space-before-function-paren": "off",
|
||||
"space-in-parens": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"space-infix-ops": "error",
|
||||
"space-unary-ops": "off",
|
||||
"spaced-comment": "off",
|
||||
"strict": "off",
|
||||
"template-curly-spacing": "error",
|
||||
"valid-jsdoc": "error",
|
||||
"vars-on-top": "off",
|
||||
"wrap-iife": "error",
|
||||
"wrap-regex": "error",
|
||||
"yield-star-spacing": "error",
|
||||
"yoda": [
|
||||
"error",
|
||||
"never"
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ language: node_js
|
|||
node_js:
|
||||
- stable
|
||||
|
||||
sudo: false
|
||||
sudo: false
|
||||
|
|
|
|||
|
|
@ -79,6 +79,3 @@ Type checks are generally already irreducible expressions and having micro-modul
|
|||
You should be trying to reduce the number of DOM operations or reduce algorithmic complexity in a hot spot. Anything else is likely a waste of time. Specifically, micro-optimizations like caching array lengths, caching object property values and inlining functions won't have any positive impact in modern javascript engines.
|
||||
|
||||
Keep object properties consistent (i.e. ensure the data objects always have the same properties and that properties are always in the same order) to allow the engine to keep using JIT'ed structs instead of hashmaps. Always place null checks first in compound type checking expressions to allow the Javascript engine to optimize to type-specific code paths. Prefer for loops over Array methods and try to pull conditionals out of loops if possible.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ module.exports = function(root, renderer, pubsub, callback) {
|
|||
if (e.redraw !== false) run()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (pubsub != null) {
|
||||
if (root.redraw) pubsub.unsubscribe(root.redraw)
|
||||
pubsub.subscribe(run)
|
||||
}
|
||||
|
||||
|
||||
return root.redraw = run
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module.exports = function(renderer, pubsub) {
|
|||
var run = autoredraw(root, renderer, pubsub, function() {
|
||||
renderer.render(root, {tag: component})
|
||||
})
|
||||
|
||||
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,6 @@ module.exports = function($window, renderer, pubsub) {
|
|||
route.prefix = router.setPrefix
|
||||
route.setPath = router.setPath
|
||||
route.getPath = router.getPath
|
||||
|
||||
|
||||
return route
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@
|
|||
<script src="../../api/autoredraw.js"></script>
|
||||
<script src="../../api/mount.js"></script>
|
||||
<script src="../../api/router.js"></script>
|
||||
|
||||
|
||||
<script src="./test-throttle.js"></script>
|
||||
<script src="./test-pubsub.js"></script>
|
||||
<script src="./test-autoredraw.js"></script>
|
||||
<script src="./test-mount.js"></script>
|
||||
<script src="./test-router.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -17,79 +17,79 @@ o.spec("autoredraw", function() {
|
|||
pubsub = apiPubSub()
|
||||
spy = o.spy()
|
||||
})
|
||||
|
||||
|
||||
o("returns self-trigger", function() {
|
||||
var run = autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
||||
run()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("null renderer doesn't throw", function(done) {
|
||||
autoredraw(root, null, pubsub, spy)
|
||||
done()
|
||||
})
|
||||
|
||||
|
||||
o("null pubsub doesn't throw", function(done) {
|
||||
autoredraw(root, renderer, null, spy)
|
||||
done()
|
||||
})
|
||||
|
||||
|
||||
o("registers onevent", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
||||
renderer.render(root, {tag: "div", attrs: {onclick: function() {}}})
|
||||
|
||||
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("registers pubsub", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("re-registering pubsub works", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("throttles", function(done) {
|
||||
var run = autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
||||
run()
|
||||
run()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
|
||||
o("does not redraw if e.redraw is false", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
|
||||
renderer.render(root, {tag: "div", attrs: {onclick: function(e) {e.redraw = false}}})
|
||||
|
||||
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -11,34 +11,34 @@ var apiMounter = require("../../api/mount")
|
|||
o.spec("mount", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redraw, mount
|
||||
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = domMock()
|
||||
|
||||
|
||||
root = $window.document.body
|
||||
|
||||
|
||||
redraw = apiPubSub()
|
||||
mount = apiMounter(coreRenderer($window), redraw)
|
||||
})
|
||||
|
||||
|
||||
o("renders into `root`", function() {
|
||||
mount(root, {
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
})
|
||||
|
||||
|
||||
o("redraws on events", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var onclick = o.spy()
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
|
||||
mount(root, {
|
||||
view : function() {
|
||||
return m("div", {
|
||||
|
|
@ -48,32 +48,32 @@ o.spec("mount", function() {
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
|
||||
o(onclick.callCount).equals(1)
|
||||
o(onclick.this).equals(root.firstChild)
|
||||
o(onclick.args[0].type).equals("click")
|
||||
o(onclick.args[0].target).equals(root.firstChild)
|
||||
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
|
||||
o("event handlers can skip redraw", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
|
||||
mount(root, {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
|
|
@ -85,23 +85,23 @@ o.spec("mount", function() {
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
|
||||
// Wrapped to ensure no redraw fired
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
|
||||
o("redraws when the render function is run", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
|
||||
|
||||
mount(root, {
|
||||
view : function() {
|
||||
return m("div", {
|
||||
|
|
@ -110,16 +110,16 @@ o.spec("mount", function() {
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
|
||||
redraw.publish()
|
||||
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,68 +8,68 @@ o.spec("pubsub", function() {
|
|||
o.beforeEach(function() {
|
||||
pubsub = apiPubSub()
|
||||
})
|
||||
|
||||
|
||||
o("shouldn't error if there are no renderers", function() {
|
||||
pubsub.publish()
|
||||
})
|
||||
|
||||
|
||||
o("should run a single renderer entry", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy.callCount).equals(4)
|
||||
})
|
||||
|
||||
|
||||
o("should run all renderer entries", function() {
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
var spy3 = o.spy()
|
||||
|
||||
|
||||
pubsub.subscribe(spy1)
|
||||
pubsub.subscribe(spy2)
|
||||
pubsub.subscribe(spy3)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
o(spy3.callCount).equals(1)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy1.callCount).equals(2)
|
||||
o(spy2.callCount).equals(2)
|
||||
o(spy3.callCount).equals(2)
|
||||
})
|
||||
|
||||
|
||||
o("should stop running after unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
pubsub.unsubscribe(spy)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("does nothing on invalid unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
pubsub.unsubscribe(null)
|
||||
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,170 +1,170 @@
|
|||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var pushStateMock = require("../../test-utils/pushStateMock")
|
||||
var domMock = require("../../test-utils/domMock")
|
||||
|
||||
var m = require("../../render/hyperscript")
|
||||
var coreRenderer = require("../../render/render")
|
||||
var apiPubSub = require("../../api/pubsub")
|
||||
var apiRouter = require("../../api/router")
|
||||
|
||||
o.spec("route", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redraw, route
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = {}
|
||||
|
||||
var dom = domMock()
|
||||
for (var key in dom) $window[key] = dom[key]
|
||||
|
||||
var loc = pushStateMock()
|
||||
for (var key in loc) $window[key] = loc[key]
|
||||
|
||||
root = $window.document.body
|
||||
|
||||
redraw = apiPubSub()
|
||||
route = apiRouter($window, coreRenderer($window), redraw)
|
||||
})
|
||||
|
||||
o("renders into `root`", function() {
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
})
|
||||
|
||||
o("redraws when render function is executed", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
redraw.publish()
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("redraws on events", function(done, timeout) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var onclick = o.spy()
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate,
|
||||
onclick: onclick,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
o(onclick.callCount).equals(1)
|
||||
o(onclick.this).equals(root.firstChild)
|
||||
o(onclick.args[0].type).equals("click")
|
||||
o(onclick.args[0].target).equals(root.firstChild)
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("event handlers can skip redraw", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var onclick = o.spy()
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate,
|
||||
onclick: function(e) {
|
||||
e.redraw = false
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
// Wrapped to ensure no redraw fired
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("changes location on route.link", function() {
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
route.prefix("?")
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("a", {
|
||||
href: "/test",
|
||||
oncreate: route.link
|
||||
})
|
||||
}
|
||||
},
|
||||
"/test" : {
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
o($window.location.href).equals("http://localhost/?/")
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o($window.location.href).equals("http://localhost/?/test")
|
||||
})
|
||||
})
|
||||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var pushStateMock = require("../../test-utils/pushStateMock")
|
||||
var domMock = require("../../test-utils/domMock")
|
||||
|
||||
var m = require("../../render/hyperscript")
|
||||
var coreRenderer = require("../../render/render")
|
||||
var apiPubSub = require("../../api/pubsub")
|
||||
var apiRouter = require("../../api/router")
|
||||
|
||||
o.spec("route", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redraw, route
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = {}
|
||||
|
||||
var dom = domMock()
|
||||
for (var key in dom) $window[key] = dom[key]
|
||||
|
||||
var loc = pushStateMock()
|
||||
for (var key in loc) $window[key] = loc[key]
|
||||
|
||||
root = $window.document.body
|
||||
|
||||
redraw = apiPubSub()
|
||||
route = apiRouter($window, coreRenderer($window), redraw)
|
||||
})
|
||||
|
||||
o("renders into `root`", function() {
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
})
|
||||
|
||||
o("redraws when render function is executed", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
redraw.publish()
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("redraws on events", function(done, timeout) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var onclick = o.spy()
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate,
|
||||
onclick: onclick,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
o(onclick.callCount).equals(1)
|
||||
o(onclick.this).equals(root.firstChild)
|
||||
o(onclick.args[0].type).equals("click")
|
||||
o(onclick.args[0].target).equals(root.firstChild)
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(1)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("event handlers can skip redraw", function(done) {
|
||||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
var onclick = o.spy()
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate,
|
||||
onclick: function(e) {
|
||||
e.redraw = false
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
// Wrapped to ensure no redraw fired
|
||||
setTimeout(function() {
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("changes location on route.link", function() {
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
route.prefix("?")
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("a", {
|
||||
href: "/test",
|
||||
oncreate: route.link
|
||||
})
|
||||
}
|
||||
},
|
||||
"/test" : {
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
o($window.location.href).equals("http://localhost/?/")
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o($window.location.href).equals("http://localhost/?/test")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -11,74 +11,74 @@ o.spec("throttle", function() {
|
|||
spy = o.spy()
|
||||
throttled = throttle(spy)
|
||||
})
|
||||
|
||||
|
||||
o("runs first call synchronously", function() {
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("throttles subsequent synchronous calls", function(done) {
|
||||
throttled()
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET) //this delay is much higher than 16.6ms due to setTimeout clamp and other runtime costs
|
||||
})
|
||||
|
||||
|
||||
o("calls after threshold", function(done) {
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
setTimeout(function(t) {
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
o("throttles before threshold", function(done) {
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
callAsync(function(t) {
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o("it only runs once per tick", function(done) {
|
||||
throttled()
|
||||
throttled()
|
||||
throttled()
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
|
||||
o("it supports forcing a synchronous redraw", function() {
|
||||
throttled()
|
||||
throttled()
|
||||
throttled(true)
|
||||
|
||||
|
||||
o(spy.callCount).equals(2)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ function resolve(dir, data) {
|
|||
var replacements = []
|
||||
data = data.replace(/((?:var|let|const|)[\t ]*)([\w_$\.]+)(\s*=\s*)require\(([^\)]+)\)/g, function(match, def, variable, eq, dep) {
|
||||
usedVariables[variable] = usedVariables[variable] ? usedVariables[variable]++ : 1
|
||||
|
||||
|
||||
var filename = new Function("return " + dep).call()
|
||||
var normalized = path.resolve(dir, filename)
|
||||
var pathname = path.dirname(normalized)
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ To learn more about components, [see the components page](components.md).
|
|||
|
||||
### Lifecycle methods
|
||||
|
||||
Vnodes and components can have lifecycle methods (also known as *hooks*), which are called at various points during the lifetime of a DOM element. The lifecycle methods supported by Mithril are: `oninit`, `oncreate`, `onupdate`, `onbeforeremove`, `onremove`, and `onbeforeupdate`.
|
||||
Vnodes and components can have lifecycle methods (also known as *hooks*), which are called at various points during the lifetime of a DOM element. The lifecycle methods supported by Mithril are: `oninit`, `oncreate`, `onupdate`, `onbeforeremove`, `onremove`, and `onbeforeupdate`.
|
||||
|
||||
Lifecycle methods are defined in the same way as DOM event handlers, but receive the vnode as an argument, instead of an Event object:
|
||||
|
||||
|
|
@ -309,7 +309,7 @@ m("ul", users.map(function(u) { // <ul>
|
|||
})) // </ul>
|
||||
|
||||
// ES6:
|
||||
// m("ul", users.map(u =>
|
||||
// m("ul", users.map(u =>
|
||||
// m("li", u.name)
|
||||
// ))
|
||||
```
|
||||
|
|
@ -392,7 +392,7 @@ var BadListComponent = {
|
|||
for (var i = 0; i < vnode.attrs.items.length; i++) {
|
||||
list.push(m("li", vnode.attrs.items[i]))
|
||||
}
|
||||
|
||||
|
||||
return m("ul", list)
|
||||
}
|
||||
}
|
||||
|
|
@ -409,4 +409,4 @@ var BetterListComponent = {
|
|||
}))
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -150,4 +150,3 @@ var things = [
|
|||
{id: 1, name: "Cup"},
|
||||
]
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -204,4 +204,4 @@ If a design-based solution is not feasible, and you must optimize a UI with a la
|
|||
|
||||
Avoid applying the optimization to other areas of your application "just-in-case". Remember that, generally speaking, more code incurs a higher maintenance cost than less code, and `onbeforeupdate` related bugs can be especially difficult to troubleshoot if you rely on object identity for its conditional checks.
|
||||
|
||||
Again, **the `onbeforeupdate` hook should only be used as a last resort.**
|
||||
Again, **the `onbeforeupdate` hook should only be used as a last resort.**
|
||||
|
|
|
|||
|
|
@ -33,4 +33,3 @@ This method is internally called by [`m.mount()`](mount.md) and [`m.route()`](ro
|
|||
The `m.render` module is similar in scope to view libraries like Knockout, React and Vue. It is less than 500 lines of code (3kb min+gzip) and implements a virtual DOM diffing engine with a modern search space reduction algorithm and DOM recycling, which translate to top-of-class performance, both in terms of initial page load and re-rendering. It has no dependencies on other parts of Mithril and can be used as a standalone library.
|
||||
|
||||
Despite being incredibly small, the render module is fully functional and self-suficient. It supports everything you might expect: SVG, custom elements, and all valid attributes and events - without any weird case-sensitive edge cases or exceptions. Of course, it also fully supports [components](components.md) and [lifecycle methods](lifecycle-methods.md).
|
||||
|
||||
|
|
|
|||
|
|
@ -31,4 +31,4 @@ A splat argument means that if the last argument is an array, you can omit the s
|
|||
|
||||
In the example at the top, this means that `m("div", {id: "foo"}, ["a", "b", "c"])` can also be written as `m("div", {id: "foo"}, "a", "b", "c")`.
|
||||
|
||||
Splats are useful in some compile-to-js languages such as Coffeescript, and also allow helpful shorthands for some common use cases.
|
||||
Splats are useful in some compile-to-js languages such as Coffeescript, and also allow helpful shorthands for some common use cases.
|
||||
|
|
|
|||
|
|
@ -101,10 +101,10 @@ Here's the example snippet for the [Facebook Like button](https://developers.fac
|
|||
}(document, 'script', 'facebook-jssdk'));</script>
|
||||
|
||||
<!-- Your like button code -->
|
||||
<div class="fb-like"
|
||||
data-href="http://www.your-domain.com/your-page.html"
|
||||
data-layout="standard"
|
||||
data-action="like"
|
||||
<div class="fb-like"
|
||||
data-href="http://www.your-domain.com/your-page.html"
|
||||
data-layout="standard"
|
||||
data-action="like"
|
||||
data-show-faces="true">
|
||||
</div>
|
||||
```
|
||||
|
|
@ -149,4 +149,4 @@ Unicode characters for accented characters can be typed using a keyboard layout
|
|||
|
||||
All characters that are representable as HTML entities have unicode counterparts, including non-visible characters such as ` ` and `­`.
|
||||
|
||||
To avoid encoding issues, you should set the file encoding to UTF-8 on the Javascript file, as well as add the `<meta charset="utf-8">` meta tag in the host HTML file.
|
||||
To avoid encoding issues, you should set the file encoding to UTF-8 on the Javascript file, as well as add the `<meta charset="utf-8">` meta tag in the host HTML file.
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ In `v1.x` there is no more `controller` property in components, use `oninit` ins
|
|||
m.mount(document.body, {
|
||||
controller : function() {
|
||||
var ctrl = this;
|
||||
|
||||
|
||||
ctrl.fooga = 1;
|
||||
},
|
||||
|
||||
|
||||
view : function(ctrl) {
|
||||
return m("p", ctrl.fooga);
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ m.mount(document.body, {
|
|||
oninit : function(vnode) {
|
||||
vnode.state.fooga = 1;
|
||||
},
|
||||
|
||||
|
||||
view : function(vnode) {
|
||||
return m("p", vnode.state.fooga);
|
||||
}
|
||||
|
|
@ -113,13 +113,13 @@ m.mount(document.body, {
|
|||
m.mount(document.body, {
|
||||
oninit : function(vnode) {
|
||||
var ctrl = this; // this is bound to vnode.state by default
|
||||
|
||||
|
||||
ctrl.fooga = 1;
|
||||
},
|
||||
|
||||
|
||||
view : function(vnode) {
|
||||
var ctrl = this; // this is bound to vnode.state by default
|
||||
|
||||
|
||||
return m("p", ctrl.fooga);
|
||||
}
|
||||
});
|
||||
|
|
@ -136,7 +136,7 @@ var component = {
|
|||
controller : function(options) {
|
||||
// options.fooga === 1
|
||||
},
|
||||
|
||||
|
||||
view : function(ctrl, options) {
|
||||
// options.fooga == 1
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ var component = {
|
|||
oninit : function(vnode) {
|
||||
// vnode.attrs.fooga === 1
|
||||
},
|
||||
|
||||
|
||||
view : function(vnode) {
|
||||
// vnode.attrs.fooga == 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,4 +99,4 @@ Only element tag names and components can be the first argument of the `m()` fun
|
|||
|
||||
The `mithril/render/node` module is used by Mithril to generate all vnodes. This ensures modern Javascript engines can optimize virtual dom diffing by always compiling vnodes to the same hidden class.
|
||||
|
||||
When creating libraries that emit vnodes, you should use this module instead of writing naked Javascript objects in order to ensure a high level of rendering performance.
|
||||
When creating libraries that emit vnodes, you should use this module instead of writing naked Javascript objects in order to ensure a high level of rendering performance.
|
||||
|
|
|
|||
5
index.js
5
index.js
|
|
@ -1,4 +1,7 @@
|
|||
"use strict"
|
||||
|
||||
/* eslint-disable global-require */
|
||||
|
||||
;(function () {
|
||||
var Promise = require("./promise/promise")
|
||||
var m = require("./render/hyperscript")
|
||||
|
|
@ -18,4 +21,4 @@
|
|||
|
||||
if (typeof module === "object") module.exports = m
|
||||
else window.m = m
|
||||
})()
|
||||
}())
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ Assertions may have descriptions:
|
|||
```javascript
|
||||
o("addition", function() {
|
||||
o(1 + 1).equals(2)("addition should work")
|
||||
|
||||
|
||||
/* in ES6, the following syntax is also possible
|
||||
o(1 + 1).equals(2) `addition should work`
|
||||
*/
|
||||
|
|
@ -110,7 +110,7 @@ o.spec("call()", function() {
|
|||
o("works", function() {
|
||||
var spy = o.spy()
|
||||
call(spy, 1)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.args[0]).equals(1)
|
||||
})
|
||||
|
|
@ -132,7 +132,7 @@ By default, asynchronous tests time out after 20ms. This can be changed on a per
|
|||
```javascript
|
||||
o("setTimeout calls callback", function(done, timeout) {
|
||||
timeout(50) //wait 50ms before bailing out of the test
|
||||
|
||||
|
||||
setTimeout(done, 30)
|
||||
})
|
||||
```
|
||||
|
|
@ -151,15 +151,15 @@ o.spec("math", function() {
|
|||
o.beforeEach(function() {
|
||||
acc = 0
|
||||
})
|
||||
|
||||
|
||||
o("addition", function() {
|
||||
acc += 1
|
||||
|
||||
|
||||
o(acc).equals(1)
|
||||
})
|
||||
o("subtraction", function() {
|
||||
acc -= 1
|
||||
|
||||
|
||||
o(acc).equals(-1)
|
||||
})
|
||||
})
|
||||
|
|
@ -180,16 +180,16 @@ o.spec("math", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
//tests only run after async hooks complete
|
||||
o("addition", function() {
|
||||
acc += 1
|
||||
|
||||
|
||||
o(acc).equals(1)
|
||||
})
|
||||
o("subtraction", function() {
|
||||
acc -= 1
|
||||
|
||||
|
||||
o(acc).equals(-1)
|
||||
})
|
||||
})
|
||||
|
|
@ -204,7 +204,7 @@ o.spec("math", function() {
|
|||
o("addition", function() {
|
||||
o(1 + 1).equals(2)
|
||||
})
|
||||
|
||||
|
||||
//only this test will be run, regardless of how many groups there are
|
||||
o.only("subtraction", function() {
|
||||
o(1 - 1).notEquals(2)
|
||||
|
|
|
|||
|
|
@ -43,4 +43,4 @@ traverseDirectory(".", function(pathname, stat, children) {
|
|||
|
||||
process.on("unhandledRejection", function(e) {
|
||||
console.log("Uncaught (in promise) " + e.stack)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
node cli
|
||||
node cli
|
||||
|
|
|
|||
|
|
@ -32,21 +32,21 @@ module.exports = new function init() {
|
|||
o.run = function() {
|
||||
start = new Date
|
||||
test(spec, [], [], report)
|
||||
|
||||
|
||||
function test(spec, pre, post, finalize) {
|
||||
pre = [].concat(pre, spec["__beforeEach"] || [])
|
||||
post = [].concat(spec["__afterEach"] || [], post)
|
||||
series([].concat(spec["__before"] || [], Object.keys(spec).map(function(key) {
|
||||
return function(done, timeout) {
|
||||
timeout(Infinity)
|
||||
|
||||
|
||||
if (key.slice(0, 2) === "__") return done()
|
||||
if (only !== null && spec[key] !== only && typeof only === typeof spec[key]) return done()
|
||||
subjects.push(key)
|
||||
var type = typeof spec[key]
|
||||
if (type === "object") test(spec[key], pre, post, pop)
|
||||
if (type === "function") series([].concat(pre, spec[key], post, pop))
|
||||
|
||||
|
||||
function pop() {
|
||||
subjects.pop()
|
||||
done()
|
||||
|
|
@ -58,11 +58,11 @@ module.exports = new function init() {
|
|||
function series(fns) {
|
||||
var cursor = 0
|
||||
next()
|
||||
|
||||
|
||||
function next() {
|
||||
stack++
|
||||
if (cursor === fns.length) return
|
||||
|
||||
|
||||
var fn = fns[cursor++]
|
||||
if (fn.length > 0) {
|
||||
var timeout = 0, delay = 40, s = new Date
|
||||
|
|
@ -108,12 +108,12 @@ module.exports = new function init() {
|
|||
ctx[name] = predicate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
define("equals", "should equal", function(a, b) {return a === b})
|
||||
define("notEquals", "should not equal", function(a, b) {return a !== b})
|
||||
define("deepEquals", "should deep equal", deepEqual)
|
||||
define("notDeepEquals", "should not deep equal", function(a, b) {return !deepEqual(a, b)})
|
||||
|
||||
|
||||
function isArguments(a) {
|
||||
if ("callee" in a) {
|
||||
for (var i in a) if (i === "callee") return false
|
||||
|
|
@ -184,7 +184,7 @@ module.exports = new function init() {
|
|||
function highlight(message) {
|
||||
return hasProcess ? "\x1b[31m" + message + "\x1b[0m" : "%c" + message + "%c "
|
||||
}
|
||||
|
||||
|
||||
function report() {
|
||||
var status = 0
|
||||
for (var i = 0, r; r = results[i]; i++) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
<body>
|
||||
<script src="../../module/module.js"></script>
|
||||
<script src="../../test-utils/callAsync.js"></script>
|
||||
|
||||
|
||||
<script src="../../ospec/ospec.js"></script>
|
||||
<script src="test-ospec.js"></script>
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -21,22 +21,22 @@ new function(o) {
|
|||
o.spec("ospec", function() {
|
||||
o.spec("sync", function() {
|
||||
var a = 0, b = 0
|
||||
|
||||
|
||||
o.before(function test() {a = 1})
|
||||
o.after(function test() {a = 0})
|
||||
|
||||
|
||||
o.beforeEach(function test() {b = 1})
|
||||
o.afterEach(function test() {b = 0})
|
||||
|
||||
|
||||
o("assertions", function test() {
|
||||
var spy = o.spy()
|
||||
spy(a)
|
||||
|
||||
|
||||
o(a).equals(b)
|
||||
o(a).notEquals(2)
|
||||
o({a: [1, 2], b: 3}).deepEquals({a: [1, 2], b: 3})
|
||||
o([{a: 1, b: 2}, {c: 3}]).deepEquals([{a: 1, b: 2}, {c: 3}])
|
||||
|
||||
|
||||
var values = ["a", "", 1, 0, true, false, null, undefined, Date(0), ["a"], [], function() {return arguments}.call(), new Uint8Array(), {a: 1}, {}]
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
|
|
@ -44,7 +44,7 @@ o.spec("ospec", function() {
|
|||
else o(values[i]).notDeepEquals(values[j])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.args.length).equals(1)
|
||||
o(spy.args[0]).equals(1)
|
||||
|
|
@ -52,7 +52,7 @@ o.spec("ospec", function() {
|
|||
})
|
||||
o.spec("async", function() {
|
||||
var a = 0, b = 0
|
||||
|
||||
|
||||
o.before(function test(done) {
|
||||
callAsync(function() {
|
||||
a = 1
|
||||
|
|
@ -65,7 +65,7 @@ o.spec("ospec", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.beforeEach(function test(done) {
|
||||
callAsync(function() {
|
||||
b = 1
|
||||
|
|
@ -78,15 +78,15 @@ o.spec("ospec", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o("async hooks", function test(done) {
|
||||
callAsync(function() {
|
||||
var spy = o.spy()
|
||||
spy(a)
|
||||
|
||||
|
||||
o(a).equals(b)
|
||||
o(a).equals(1)("a and b should be initialized")
|
||||
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
var Promise = function(executor) {
|
||||
if (!(this instanceof Promise)) throw new Error("Promise must be called with `new`")
|
||||
if (typeof executor !== "function") throw new TypeError("executor must be a function")
|
||||
|
||||
|
||||
var self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false)
|
||||
var instance = self._instance = {resolvers: resolvers, rejectors: rejectors}
|
||||
var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout
|
||||
|
|
@ -41,7 +41,7 @@ var Promise = function(executor) {
|
|||
var onerror = run(rejectCurrent)
|
||||
try {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)}
|
||||
}
|
||||
|
||||
|
||||
executeOnce(executor)
|
||||
}
|
||||
Promise.prototype.then = function(onFulfilled, onRejection) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<script src="../../promise/promise.js"></script>
|
||||
<script src="test-promise.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -24,31 +24,31 @@ o.spec("promise", function() {
|
|||
o.spec("return value", function() {
|
||||
o("static resolve returns promise", function() {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
o(promise instanceof Promise).equals(true)
|
||||
})
|
||||
o("static resolve returns promise", function() {
|
||||
var promise = Promise.reject()
|
||||
promise.catch(function() {})
|
||||
|
||||
|
||||
o(promise instanceof Promise).equals(true)
|
||||
})
|
||||
o("static resolve with promise input returns same promise", function() {
|
||||
var resolved = Promise.resolve(1)
|
||||
var promise = Promise.resolve(resolved)
|
||||
|
||||
|
||||
o(promise).equals(resolved)
|
||||
})
|
||||
o("then returns promise", function(done) {
|
||||
var promise = Promise.resolve(1)
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
}).then(done)
|
||||
})
|
||||
o("catch returns promise", function(done) {
|
||||
var promise = Promise.reject(1)
|
||||
|
||||
|
||||
promise.catch(function(value) {
|
||||
o(value).equals(1)
|
||||
}).then(done)
|
||||
|
|
@ -62,10 +62,10 @@ o.spec("promise", function() {
|
|||
resolve(2)
|
||||
callAsync(function() {resolve(3)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
callCount++
|
||||
|
||||
|
||||
o(value).equals(1)
|
||||
o(callCount).equals(1)
|
||||
done()
|
||||
|
|
@ -77,7 +77,7 @@ o.spec("promise", function() {
|
|||
reject(2)
|
||||
callAsync(function() {reject(3)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -85,9 +85,9 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("resolves asynchronously", function(done) {
|
||||
var state = 0
|
||||
|
||||
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
state = 1
|
||||
promise.then(function(value) {
|
||||
o(state).equals(2)
|
||||
|
|
@ -97,7 +97,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("resolves via static method", function(done) {
|
||||
var promise = Promise.resolve(1)
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -107,7 +107,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
callAsync(function() {resolve(1)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -117,7 +117,7 @@ o.spec("promise", function() {
|
|||
var promise = Promise.resolve(1)
|
||||
var a = promise.then(function(value) {return value + 1})
|
||||
var b = promise.then(function(value) {return value + 2})
|
||||
|
||||
|
||||
a.then(function(aValue) {
|
||||
b.then(function(bValue) {
|
||||
o(aValue).equals(2)
|
||||
|
|
@ -130,12 +130,12 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve) {
|
||||
callAsync(function() {resolve(promise)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, done)
|
||||
})
|
||||
o("non-function onFulfilled is ignored", function(done) {
|
||||
var promise = Promise.resolve(1)
|
||||
|
||||
|
||||
promise.then(null, null).then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -143,7 +143,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("non-function onFulfilled is ignored", function(done) {
|
||||
var promise = Promise.resolve(1)
|
||||
|
||||
|
||||
promise.then(null).then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -158,10 +158,10 @@ o.spec("promise", function() {
|
|||
reject(2)
|
||||
callAsync(function() {reject(3)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
callCount++
|
||||
|
||||
|
||||
o(value).equals(1)
|
||||
o(callCount).equals(1)
|
||||
done()
|
||||
|
|
@ -173,7 +173,7 @@ o.spec("promise", function() {
|
|||
resolve(2)
|
||||
callAsync(function() {resolve(3)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -181,9 +181,9 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("rejects asynchronously", function(done) {
|
||||
var state = 0
|
||||
|
||||
|
||||
var promise = Promise.reject()
|
||||
|
||||
|
||||
state = 1
|
||||
promise.then(null, function(value) {
|
||||
o(state).equals(2)
|
||||
|
|
@ -194,7 +194,7 @@ o.spec("promise", function() {
|
|||
o("does not catch itself", function(done) {
|
||||
var callCount = 0
|
||||
var promise = Promise.resolve().then(function() {throw 1}, function() {callCount++})
|
||||
|
||||
|
||||
promise.then(null, function() {
|
||||
o(callCount).equals(0)
|
||||
done()
|
||||
|
|
@ -202,7 +202,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("rejects via static method", function(done) {
|
||||
var promise = Promise.reject(1)
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
return value
|
||||
|
|
@ -215,7 +215,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
reject(1)
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -225,7 +225,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
callAsync(function() {reject(1)})
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -235,7 +235,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
throw 1
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -243,7 +243,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("rejects on fulfillment error", function(done) {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
throw 1
|
||||
}).then(null, function(value) {
|
||||
|
|
@ -253,7 +253,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("rejects on rejection error", function(done) {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
throw 1
|
||||
}).then(null, function() {
|
||||
|
|
@ -265,7 +265,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("non-function onRejected is ignored", function(done) {
|
||||
var promise = Promise.reject(1)
|
||||
|
||||
|
||||
promise.then(function() {}, null).then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -275,7 +275,7 @@ o.spec("promise", function() {
|
|||
o.spec("promise absorption", function() {
|
||||
o("absorbs resolved promise via static resolver", function(done) {
|
||||
var promise = Promise.resolve(Promise.resolve(1))
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
}).then(done)
|
||||
|
|
@ -285,7 +285,7 @@ o.spec("promise", function() {
|
|||
var p = Promise.resolve(1)
|
||||
resolve(p)
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -293,7 +293,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("absorbs resolved promise on fulfillment", function(done) {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
return Promise.resolve(1)
|
||||
}).then(function(value) {
|
||||
|
|
@ -303,7 +303,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("absorbs rejected promise via static resolver", function(done) {
|
||||
var promise = Promise.resolve(Promise.reject(1))
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -313,7 +313,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
resolve(Promise.reject(1))
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -321,7 +321,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("absorbs rejected promise on fulfillment", function(done) {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
return Promise.reject(1)
|
||||
}).then(null, function(value) {
|
||||
|
|
@ -334,7 +334,7 @@ o.spec("promise", function() {
|
|||
setTimeout(function() {resolve(1)}, 10)
|
||||
})
|
||||
var promise = Promise.resolve(pending)
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -347,7 +347,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
resolve(pending)
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -358,7 +358,7 @@ o.spec("promise", function() {
|
|||
setTimeout(function() {resolve(1)}, 10)
|
||||
})
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
return pending
|
||||
}).then(function(value) {
|
||||
|
|
@ -371,7 +371,7 @@ o.spec("promise", function() {
|
|||
setTimeout(function() {reject(1)}, 10)
|
||||
})
|
||||
var promise = Promise.resolve(pending)
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -384,7 +384,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
resolve(pending)
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -395,7 +395,7 @@ o.spec("promise", function() {
|
|||
setTimeout(function() {reject(1)}, 10)
|
||||
})
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
return pending
|
||||
}).then(null, function(value) {
|
||||
|
|
@ -405,7 +405,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("does not absorb resolved promise via static rejector", function(done) {
|
||||
var promise = Promise.reject(Promise.resolve(1))
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value instanceof Promise).equals(true)
|
||||
done()
|
||||
|
|
@ -415,7 +415,7 @@ o.spec("promise", function() {
|
|||
var rejected = Promise.reject(1)
|
||||
rejected.catch(function() {})
|
||||
var promise = Promise.reject(rejected)
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value instanceof Promise).equals(true)
|
||||
done()
|
||||
|
|
@ -425,7 +425,7 @@ o.spec("promise", function() {
|
|||
var promise = new Promise(function(resolve, reject) {
|
||||
reject(Promise.resolve(1))
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value instanceof Promise).equals(true)
|
||||
done()
|
||||
|
|
@ -437,7 +437,7 @@ o.spec("promise", function() {
|
|||
rejected.catch(function() {})
|
||||
reject(rejected)
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value instanceof Promise).equals(true)
|
||||
done()
|
||||
|
|
@ -445,7 +445,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("does not absorb resolved promise on fulfillment error", function(done) {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
throw Promise.resolve(1)
|
||||
}).then(null, function(value) {
|
||||
|
|
@ -455,7 +455,7 @@ o.spec("promise", function() {
|
|||
})
|
||||
o("does not absorb rejected promise on fulfillment error", function(done) {
|
||||
var promise = Promise.resolve()
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
var rejected = Promise.reject(1)
|
||||
rejected.catch(function() {})
|
||||
|
|
@ -468,7 +468,7 @@ o.spec("promise", function() {
|
|||
o("promise stays pending if absorbed promise is pending", function(done) {
|
||||
var promise = new Promise(function(resolve) {resolve()})
|
||||
var fulfilled = false, rejected = false
|
||||
|
||||
|
||||
promise.then(function() {
|
||||
return new Promise(function() {})
|
||||
}).then(function() {
|
||||
|
|
@ -476,7 +476,7 @@ o.spec("promise", function() {
|
|||
}, function() {
|
||||
rejected = false
|
||||
})
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
o(fulfilled).equals(false)
|
||||
o(rejected).equals(false)
|
||||
|
|
@ -490,7 +490,7 @@ o.spec("promise", function() {
|
|||
resolve(resolved)
|
||||
}, 10)
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(1)
|
||||
done()
|
||||
|
|
@ -573,7 +573,7 @@ o.spec("promise", function() {
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(readCount).equals(1)
|
||||
done()
|
||||
|
|
@ -590,7 +590,7 @@ o.spec("promise", function() {
|
|||
res(1)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
promise.then(function(value) {
|
||||
o(value).equals(2)
|
||||
done()
|
||||
|
|
@ -605,11 +605,11 @@ o.spec("promise", function() {
|
|||
})
|
||||
throw 3
|
||||
})
|
||||
|
||||
|
||||
promise.then(null, function(value) {
|
||||
o(value).equals(2)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
module.exports = function(object) {
|
||||
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
|
||||
|
||||
|
||||
var args = []
|
||||
for (var key in object) {
|
||||
destructure(key, object[key])
|
||||
}
|
||||
return args.join("&")
|
||||
|
||||
|
||||
function destructure(key, value) {
|
||||
if (value instanceof Array) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
|
|
@ -22,4 +22,4 @@ module.exports = function(object) {
|
|||
}
|
||||
else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
module.exports = function(string) {
|
||||
if (string === "" || string == null) return {}
|
||||
if (string.charAt(0) === "?") string = string.slice(1)
|
||||
|
||||
|
||||
var entries = string.split("&"), data = {}, counters = {}
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var entry = entries[i].split("=")
|
||||
var key = decodeURIComponent(entry[0])
|
||||
var value = entry.length === 2 ? decodeURIComponent(entry[1]) : ""
|
||||
|
||||
|
||||
//TODO refactor out
|
||||
var number = Number(value)
|
||||
if (value !== "" && !isNaN(number) || value === "NaN") value = number
|
||||
|
|
@ -19,7 +19,7 @@ module.exports = function(string) {
|
|||
var date = new Date(value)
|
||||
if (!isNaN(date.getTime())) value = date
|
||||
}
|
||||
|
||||
|
||||
var levels = key.split(/\]\[?|\[/)
|
||||
var cursor = data
|
||||
if (key.indexOf("[") > -1) levels.pop()
|
||||
|
|
@ -39,4 +39,4 @@ module.exports = function(string) {
|
|||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<script src="../../querystring/build.js"></script>
|
||||
<script src="test-parseQueryString.js"></script>
|
||||
<script src="test-buildQueryString.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -6,77 +6,77 @@ var buildQueryString = require("../../querystring/build")
|
|||
o.spec("buildQueryString", function() {
|
||||
o("handles flat object", function() {
|
||||
var string = buildQueryString({a: "b", c: 1})
|
||||
|
||||
|
||||
o(string).equals("a=b&c=1")
|
||||
})
|
||||
o("handles escaped values", function() {
|
||||
var data = buildQueryString({";:@&=+$,/?%#": ";:@&=+$,/?%#"})
|
||||
|
||||
|
||||
o(data).equals("%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23=%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23")
|
||||
})
|
||||
o("handles unicode", function() {
|
||||
var data = buildQueryString({"ö": "ö"})
|
||||
|
||||
|
||||
o(data).equals("%C3%B6=%C3%B6")
|
||||
})
|
||||
o("handles nested object", function() {
|
||||
var string = buildQueryString({a: {b: 1, c: 2}})
|
||||
|
||||
|
||||
o(string).equals("a%5Bb%5D=1&a%5Bc%5D=2")
|
||||
})
|
||||
o("handles deep nested object", function() {
|
||||
var string = buildQueryString({a: {b: {c: 1, d: 2}}})
|
||||
|
||||
|
||||
o(string).equals("a%5Bb%5D%5Bc%5D=1&a%5Bb%5D%5Bd%5D=2")
|
||||
})
|
||||
o("handles nested array", function() {
|
||||
var string = buildQueryString({a: ["x", "y"]})
|
||||
|
||||
|
||||
o(string).equals("a%5B0%5D=x&a%5B1%5D=y")
|
||||
})
|
||||
o("handles deep nested array", function() {
|
||||
var string = buildQueryString({a: [["x", "y"]]})
|
||||
|
||||
|
||||
o(string).equals("a%5B0%5D%5B0%5D=x&a%5B0%5D%5B1%5D=y")
|
||||
})
|
||||
o("handles deep nested array in object", function() {
|
||||
var string = buildQueryString({a: {b: ["x", "y"]}})
|
||||
|
||||
|
||||
o(string).equals("a%5Bb%5D%5B0%5D=x&a%5Bb%5D%5B1%5D=y")
|
||||
})
|
||||
o("handles deep nested object in array", function() {
|
||||
var string = buildQueryString({a: [{b: 1, c: 2}]})
|
||||
|
||||
|
||||
o(string).equals("a%5B0%5D%5Bb%5D=1&a%5B0%5D%5Bc%5D=2")
|
||||
})
|
||||
o("handles date", function() {
|
||||
var string = buildQueryString({a: new Date(0)})
|
||||
|
||||
|
||||
o(string).equals("a=" + encodeURIComponent(new Date(0).toString()))
|
||||
})
|
||||
o("turns null into value-less string (like jQuery)", function() {
|
||||
var string = buildQueryString({a: null})
|
||||
|
||||
|
||||
o(string).equals("a")
|
||||
})
|
||||
o("turns undefined into value-less string (like jQuery)", function() {
|
||||
var string = buildQueryString({a: undefined})
|
||||
|
||||
|
||||
o(string).equals("a")
|
||||
})
|
||||
o("turns empty string into value-less string (like jQuery)", function() {
|
||||
var string = buildQueryString({a: ""})
|
||||
|
||||
|
||||
o(string).equals("a")
|
||||
})
|
||||
o("handles zero", function() {
|
||||
var string = buildQueryString({a: 0})
|
||||
|
||||
|
||||
o(string).equals("a=0")
|
||||
})
|
||||
o("handles false", function() {
|
||||
var string = buildQueryString({a: false})
|
||||
|
||||
|
||||
o(string).equals("a=false")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ function hyperscript(selector) {
|
|||
}
|
||||
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
||||
else childList = children
|
||||
|
||||
|
||||
return Node(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
||||
}
|
||||
}
|
||||
|
|
@ -57,9 +57,9 @@ function hyperscript(selector) {
|
|||
children = []
|
||||
for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])
|
||||
}
|
||||
|
||||
|
||||
if (typeof selector === "string") return selectorCache[selector](attrs || {}, Node.normalizeChildren(children))
|
||||
|
||||
|
||||
return Node(selector, attrs && attrs.key, attrs || {}, Node.normalizeChildren(children), undefined, undefined)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@ Node.normalizeChildren = function normalizeChildren(children) {
|
|||
return children
|
||||
}
|
||||
|
||||
module.exports = Node
|
||||
module.exports = Node
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module.exports = function($window) {
|
|||
|
||||
var onevent
|
||||
function setEventCallback(callback) {return onevent = callback}
|
||||
|
||||
|
||||
//create
|
||||
function createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {
|
||||
for (var i = start; i < end; i++) {
|
||||
|
|
@ -38,7 +38,7 @@ module.exports = function($window) {
|
|||
var match = vnode.children.match(/^\s*?<(\w+)/im) || []
|
||||
var parent = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"}[match[1]] || "div"
|
||||
var temp = $doc.createElement(parent)
|
||||
|
||||
|
||||
temp.innerHTML = vnode.children
|
||||
vnode.dom = temp.firstChild
|
||||
vnode.domSize = temp.childNodes.length
|
||||
|
|
@ -65,24 +65,24 @@ module.exports = function($window) {
|
|||
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
||||
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
||||
}
|
||||
|
||||
|
||||
var attrs = vnode.attrs
|
||||
var is = attrs && attrs.is
|
||||
|
||||
|
||||
var element = ns ?
|
||||
is ? $doc.createElementNS(ns, tag, is) : $doc.createElementNS(ns, tag) :
|
||||
is ? $doc.createElement(tag, is) : $doc.createElement(tag)
|
||||
vnode.dom = element
|
||||
|
||||
|
||||
if (attrs != null) {
|
||||
setAttrs(vnode, attrs, ns)
|
||||
}
|
||||
|
||||
|
||||
if (vnode.text != null) {
|
||||
if (vnode.text !== "") element.textContent = vnode.text
|
||||
else vnode.children = [Node("#", undefined, undefined, vnode.text, undefined, undefined)]
|
||||
}
|
||||
|
||||
|
||||
if (vnode.children != null) {
|
||||
var children = vnode.children
|
||||
createNodes(element, children, 0, children.length, hooks, null, ns)
|
||||
|
|
@ -92,7 +92,7 @@ module.exports = function($window) {
|
|||
}
|
||||
function createComponent(vnode, hooks, ns) {
|
||||
vnode.state = copy(vnode.tag)
|
||||
|
||||
|
||||
initLifecycle(vnode.tag, vnode, hooks)
|
||||
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
|
||||
if (vnode.instance != null) {
|
||||
|
|
@ -112,7 +112,7 @@ module.exports = function($window) {
|
|||
else {
|
||||
var recycling = isRecyclable(old, vnodes)
|
||||
if (recycling) old = old.concat(old.pool)
|
||||
|
||||
|
||||
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
||||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldStart], v = vnodes[start]
|
||||
|
|
@ -321,7 +321,7 @@ module.exports = function($window) {
|
|||
}
|
||||
if (expected > 0) return
|
||||
}
|
||||
|
||||
|
||||
onremove(vnode)
|
||||
if (vnode.dom) {
|
||||
var count = vnode.domSize || 1
|
||||
|
|
@ -341,7 +341,7 @@ module.exports = function($window) {
|
|||
function onremove(vnode) {
|
||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
|
||||
|
||||
|
||||
var children = vnode.children
|
||||
if (children instanceof Array) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
|
|
@ -412,7 +412,7 @@ module.exports = function($window) {
|
|||
function hasIntegrationMethods(source) {
|
||||
return source != null && (source.oncreate || source.onupdate || source.onbeforeremove || source.onremove)
|
||||
}
|
||||
|
||||
|
||||
//style
|
||||
function updateStyle(element, old, style) {
|
||||
if (old === style) element.style = "", old = null
|
||||
|
|
@ -430,7 +430,7 @@ module.exports = function($window) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//event
|
||||
function updateEvent(vnode, key, value) {
|
||||
var element = vnode.dom
|
||||
|
|
@ -470,7 +470,7 @@ module.exports = function($window) {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
function copy(data) {
|
||||
if (data instanceof Array) {
|
||||
var output = []
|
||||
|
|
@ -489,7 +489,7 @@ module.exports = function($window) {
|
|||
var hooks = []
|
||||
var active = $doc.activeElement
|
||||
if (dom.vnodes == null) dom.vnodes = []
|
||||
|
||||
|
||||
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
||||
updateNodes(dom, dom.vnodes, Node.normalizeChildren(vnodes), hooks, null, undefined)
|
||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
<script src="test-input.js"></script>
|
||||
<script src="test-textContent.js"></script>
|
||||
<script src="test-component.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -15,47 +15,47 @@ o.spec("attributes", function() {
|
|||
o.spec("input readonly", function() {
|
||||
o("when input readonly is true, attribute is present", function() {
|
||||
var a = {tag: "input", attrs: {readonly: true}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
o(a.dom.attributes["readonly"].nodeValue).equals("")
|
||||
})
|
||||
o("when input readonly is false, attribute is not present", function() {
|
||||
var a = {tag: "input", attrs: {readonly: false}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
o(a.dom.attributes["readonly"]).equals(undefined)
|
||||
})
|
||||
})
|
||||
o.spec("input checked", function() {
|
||||
o("when input checked is true, attribute is not present", function() {
|
||||
var a = {tag: "input", attrs: {checked: true}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
o(a.dom.checked).equals(true)
|
||||
o(a.dom.attributes["checked"]).equals(undefined)
|
||||
})
|
||||
o("when input checked is false, attribute is not present", function() {
|
||||
var a = {tag: "input", attrs: {checked: false}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
o(a.dom.checked).equals(false)
|
||||
o(a.dom.attributes["checked"]).equals(undefined)
|
||||
})
|
||||
o("after input checked is changed by 3rd party, it can still be changed by render", function() {
|
||||
var a = {tag: "input", attrs: {checked: false}}
|
||||
var b = {tag: "input", attrs: {checked: true}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
a.dom.checked = true //setting the javascript property makes the value no longer track the state of the attribute
|
||||
a.dom.checked = false
|
||||
|
||||
|
||||
render(root, [b])
|
||||
|
||||
|
||||
o(a.dom.checked).equals(true)
|
||||
o(a.dom.attributes["checked"]).equals(undefined)
|
||||
})
|
||||
|
|
@ -63,16 +63,16 @@ o.spec("attributes", function() {
|
|||
o.spec("link href", function() {
|
||||
o("when link href is true, attribute is present", function() {
|
||||
var a = {tag: "a", attrs: {href: true}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
o(a.dom.attributes["href"]).notEquals(undefined)
|
||||
})
|
||||
o("when link href is false, attribute is not present", function() {
|
||||
var a = {tag: "a", attrs: {href: false}}
|
||||
|
||||
|
||||
render(root, [a])
|
||||
|
||||
|
||||
o(a.dom.attributes["href"]).equals(undefined)
|
||||
})
|
||||
})
|
||||
|
|
@ -85,4 +85,4 @@ o.spec("attributes", function() {
|
|||
o(a.dom.attributes["class"].nodeValue).equals("test")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
var node = {tag: component}
|
||||
|
||||
|
||||
render(root, [node])
|
||||
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
o(root.firstChild.firstChild.nodeValue).equals("b")
|
||||
|
|
@ -34,9 +34,9 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
var node = {tag: component, attrs: {id: "a"}, text: "b"}
|
||||
|
||||
|
||||
render(root, [node])
|
||||
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
o(root.firstChild.firstChild.nodeValue).equals("b")
|
||||
|
|
@ -49,7 +49,7 @@ o.spec("component", function() {
|
|||
}
|
||||
render(root, [{tag: component, attrs: {id: "a"}, text: "b"}])
|
||||
render(root, [{tag: component, attrs: {id: "c"}, text: "d"}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("c")
|
||||
o(root.firstChild.firstChild.nodeValue).equals("d")
|
||||
|
|
@ -63,7 +63,7 @@ o.spec("component", function() {
|
|||
var div = {tag: "div", key: 2}
|
||||
render(root, [{tag: component, key: 1}, div])
|
||||
render(root, [{tag: "div", key: 2}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(div.dom)
|
||||
})
|
||||
|
|
@ -74,7 +74,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: "svg", children: [{tag: component}]}])
|
||||
|
||||
|
||||
o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||
})
|
||||
o("svg works when updating across component boundary", function() {
|
||||
|
|
@ -85,7 +85,7 @@ o.spec("component", function() {
|
|||
}
|
||||
render(root, [{tag: "svg", children: [{tag: component}]}])
|
||||
render(root, [{tag: "svg", children: [{tag: component}]}])
|
||||
|
||||
|
||||
o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||
})
|
||||
})
|
||||
|
|
@ -100,7 +100,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(root.childNodes[0].nodeName).equals("LABEL")
|
||||
o(root.childNodes[1].nodeName).equals("INPUT")
|
||||
|
|
@ -112,7 +112,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("a")
|
||||
})
|
||||
|
|
@ -123,7 +123,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("")
|
||||
})
|
||||
|
|
@ -134,7 +134,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("1")
|
||||
})
|
||||
|
|
@ -145,7 +145,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("0")
|
||||
})
|
||||
|
|
@ -156,7 +156,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("true")
|
||||
})
|
||||
|
|
@ -167,7 +167,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("false")
|
||||
})
|
||||
|
|
@ -178,7 +178,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
o("can return undefined", function() {
|
||||
|
|
@ -188,7 +188,7 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
o("can update when returning fragments", function() {
|
||||
|
|
@ -202,7 +202,7 @@ o.spec("component", function() {
|
|||
}
|
||||
render(root, [{tag: component}])
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(root.childNodes[0].nodeName).equals("LABEL")
|
||||
o(root.childNodes[1].nodeName).equals("INPUT")
|
||||
|
|
@ -215,7 +215,7 @@ o.spec("component", function() {
|
|||
}
|
||||
render(root, [{tag: component}])
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.firstChild.nodeType).equals(3)
|
||||
o(root.firstChild.nodeValue).equals("a")
|
||||
})
|
||||
|
|
@ -227,7 +227,7 @@ o.spec("component", function() {
|
|||
}
|
||||
render(root, [{tag: component}])
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
o("can remove when returning fragments", function() {
|
||||
|
|
@ -241,9 +241,9 @@ o.spec("component", function() {
|
|||
}
|
||||
var div = {tag: "div", key: 2}
|
||||
render(root, [{tag: component, key: 1}, div])
|
||||
|
||||
|
||||
render(root, [{tag: "div", key: 2}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(div.dom)
|
||||
})
|
||||
|
|
@ -255,9 +255,9 @@ o.spec("component", function() {
|
|||
}
|
||||
var div = {tag: "div", key: 2}
|
||||
render(root, [{tag: component, key: 1}, div])
|
||||
|
||||
|
||||
render(root, [{tag: "div", key: 2}])
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(div.dom)
|
||||
})
|
||||
|
|
@ -268,7 +268,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
oninit: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.tag).equals(component)
|
||||
o(vnode.dom).equals(undefined)
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
|
@ -278,9 +278,9 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
var node = {tag: component}
|
||||
|
||||
|
||||
render(root, [node])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
|
|
@ -291,7 +291,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
oninit: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.tag).equals(component)
|
||||
o(vnode.dom).equals(undefined)
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
|
@ -301,9 +301,9 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
var node = {tag: component}
|
||||
|
||||
|
||||
render(root, [node])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
|
|
@ -311,7 +311,7 @@ o.spec("component", function() {
|
|||
})
|
||||
o("calls oninit before view", function() {
|
||||
var viewCalled = false
|
||||
|
||||
|
||||
render(root, {
|
||||
tag: {
|
||||
view: function() {
|
||||
|
|
@ -332,14 +332,14 @@ o.spec("component", function() {
|
|||
},
|
||||
oninit: init,
|
||||
}
|
||||
|
||||
|
||||
function view() {
|
||||
return {tag: component}
|
||||
}
|
||||
|
||||
|
||||
render(root, view())
|
||||
render(root, view())
|
||||
|
||||
|
||||
o(init.callCount).equals(1)
|
||||
})
|
||||
o("calls oncreate", function() {
|
||||
|
|
@ -347,7 +347,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
oncreate: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -357,9 +357,9 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
var node = {tag: component}
|
||||
|
||||
|
||||
render(root, [node])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
|
|
@ -373,14 +373,14 @@ o.spec("component", function() {
|
|||
},
|
||||
oncreate: create,
|
||||
}
|
||||
|
||||
|
||||
function view() {
|
||||
return {tag: component}
|
||||
}
|
||||
|
||||
|
||||
render(root, view())
|
||||
render(root, view())
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
})
|
||||
o("calls oncreate when returning fragment", function() {
|
||||
|
|
@ -388,7 +388,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
oncreate: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -398,9 +398,9 @@ o.spec("component", function() {
|
|||
}
|
||||
}
|
||||
var node = {tag: component}
|
||||
|
||||
|
||||
render(root, [node])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
|
|
@ -411,7 +411,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
onupdate: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -420,13 +420,13 @@ o.spec("component", function() {
|
|||
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(0)
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
|
|
@ -437,7 +437,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
onupdate: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -446,13 +446,13 @@ o.spec("component", function() {
|
|||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(0)
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
|
|
@ -463,7 +463,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
onremove: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -472,13 +472,13 @@ o.spec("component", function() {
|
|||
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(0)
|
||||
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
|
|
@ -487,7 +487,7 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
onremove: function(vnode) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
|
@ -496,13 +496,13 @@ o.spec("component", function() {
|
|||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(0)
|
||||
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
|
|
@ -511,24 +511,24 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
onbeforeremove: function(vnode, done) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
||||
|
||||
done()
|
||||
},
|
||||
view: function() {
|
||||
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(0)
|
||||
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
|
|
@ -537,24 +537,24 @@ o.spec("component", function() {
|
|||
var component = {
|
||||
onbeforeremove: function(vnode, done) {
|
||||
called++
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(undefined)
|
||||
o(vnode.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
||||
|
||||
done()
|
||||
},
|
||||
view: function() {
|
||||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
o(called).equals(0)
|
||||
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(called).equals(1)
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
|
|
@ -568,11 +568,11 @@ o.spec("component", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: component, key: 1}
|
||||
var updated = {tag: component, key: 1}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
})
|
||||
|
|
@ -586,12 +586,12 @@ o.spec("component", function() {
|
|||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
||||
function init(vnode) {
|
||||
o(vnode.state.data).deepEquals([{a: 1}])
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ o.spec("createElement", function() {
|
|||
o("creates element", function() {
|
||||
var vnode = {tag: "div"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("DIV")
|
||||
})
|
||||
o("creates attr", function() {
|
||||
var vnode = {tag: "div", attrs: {id: "a", title: "b"}}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("DIV")
|
||||
o(vnode.dom.attributes["id"].nodeValue).equals("a")
|
||||
o(vnode.dom.attributes["title"].nodeValue).equals("b")
|
||||
|
|
@ -29,14 +29,14 @@ o.spec("createElement", function() {
|
|||
o("creates style", function() {
|
||||
var vnode = {tag: "div", attrs: {style: {backgroundColor: "red"}}}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("DIV")
|
||||
o(vnode.dom.style.backgroundColor).equals("red")
|
||||
})
|
||||
o("creates children", function() {
|
||||
var vnode = {tag: "div", children: [{tag: "a"}, {tag: "b"}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("DIV")
|
||||
o(vnode.dom.childNodes.length).equals(2)
|
||||
o(vnode.dom.childNodes[0].nodeName).equals("A")
|
||||
|
|
@ -45,7 +45,7 @@ o.spec("createElement", function() {
|
|||
o("creates attrs and children", function() {
|
||||
var vnode = {tag: "div", attrs: {id: "a", title: "b"}, children: [{tag: "a"}, {tag: "b"}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("DIV")
|
||||
o(vnode.dom.attributes["id"].nodeValue).equals("a")
|
||||
o(vnode.dom.attributes["title"].nodeValue).equals("b")
|
||||
|
|
@ -56,7 +56,7 @@ o.spec("createElement", function() {
|
|||
o("creates svg", function() {
|
||||
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {"xlink:href": "javascript:;"}}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("svg")
|
||||
o(vnode.dom.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||
o(vnode.dom.firstChild.nodeName).equals("a")
|
||||
|
|
@ -67,13 +67,13 @@ o.spec("createElement", function() {
|
|||
o("sets attributes correctly for svg", function() {
|
||||
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", attrs: {viewBox: "0 0 100 100"}}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.attributes["viewBox"].nodeValue).equals("0 0 100 100")
|
||||
})
|
||||
o("creates mathml", function() {
|
||||
var vnode = {tag: "math", ns: "http://www.w3.org/1998/Math/MathML", children: [{tag: "mrow", ns: "http://www.w3.org/1998/Math/MathML"}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("math")
|
||||
o(vnode.dom.namespaceURI).equals("http://www.w3.org/1998/Math/MathML")
|
||||
o(vnode.dom.firstChild.nodeName).equals("mrow")
|
||||
|
|
|
|||
|
|
@ -15,27 +15,27 @@ o.spec("createFragment", function() {
|
|||
o("creates fragment", function() {
|
||||
var vnode = {tag: "[", children: [{tag: "a"}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("A")
|
||||
})
|
||||
o("handles empty fragment", function() {
|
||||
var vnode = {tag: "[", children: []}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom).equals(null)
|
||||
o(vnode.domSize).equals(0)
|
||||
})
|
||||
o("handles childless fragment", function() {
|
||||
var vnode = {tag: "["}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom).equals(null)
|
||||
o(vnode.domSize).equals(0)
|
||||
})
|
||||
o("handles multiple children", function() {
|
||||
var vnode = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.domSize).equals(2)
|
||||
o(vnode.dom.nodeName).equals("A")
|
||||
o(vnode.dom.nextSibling.nodeName).equals("B")
|
||||
|
|
@ -43,7 +43,7 @@ o.spec("createFragment", function() {
|
|||
o("handles td", function() {
|
||||
var vnode = {tag: "[", children: [{tag: "td"}]}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(null)
|
||||
o(vnode.dom.nodeName).equals("TD")
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,26 +15,26 @@ o.spec("createHTML", function() {
|
|||
o("creates HTML", function() {
|
||||
var vnode = {tag: "<", children: "<a></a>"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("A")
|
||||
})
|
||||
o("creates text HTML", function() {
|
||||
var vnode = {tag: "<", children: "a"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeValue).equals("a")
|
||||
})
|
||||
o("handles empty HTML", function() {
|
||||
var vnode = {tag: "<", children: ""}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom).equals(null)
|
||||
o(vnode.domSize).equals(0)
|
||||
})
|
||||
o("handles multiple children", function() {
|
||||
var vnode = {tag: "<", children: "<a></a><b></b>"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.domSize).equals(2)
|
||||
o(vnode.dom.nodeName).equals("A")
|
||||
o(vnode.dom.nextSibling.nodeName).equals("B")
|
||||
|
|
@ -43,11 +43,11 @@ o.spec("createHTML", function() {
|
|||
//FIXME body,head,html,frame,frameset are not supported
|
||||
//FIXME keygen is broken in Firefox
|
||||
var tags = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "big", "blockquote", /*"body",*/ "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", /*"frame", "frameset",*/ "h1", "h2", "h3", "h4", "h5", "h6", /*"head",*/ "header", "hr", /*"html",*/ "i", "iframe", "img", "input", "ins", "kbd", /*"keygen", */"label", "legend", "li", "link", "main", "map", "mark", "menu", "menuitem", "meta", "meter", "nav", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]
|
||||
|
||||
|
||||
tags.forEach(function(tag) {
|
||||
var vnode = {tag: "<", children: "<" + tag + " />"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals(tag.toUpperCase())
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ o.spec("createNodes", function() {
|
|||
{tag: "[", children: [{tag: "#", children: "d"}]},
|
||||
]
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(root.childNodes[0].nodeName).equals("A")
|
||||
o(root.childNodes[1].nodeValue).equals("b")
|
||||
|
|
@ -36,7 +36,7 @@ o.spec("createNodes", function() {
|
|||
{tag: "[", children: [{tag: "#", children: "d"}]},
|
||||
]
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(root.childNodes[0].nodeName).equals("A")
|
||||
o(root.childNodes[1].nodeValue).equals("b")
|
||||
|
|
@ -52,7 +52,7 @@ o.spec("createNodes", function() {
|
|||
{tag: "[", children: [{tag: "#", children: "d"}]},
|
||||
]
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(root.childNodes[0].nodeName).equals("A")
|
||||
o(root.childNodes[1].nodeValue).equals("b")
|
||||
|
|
|
|||
|
|
@ -15,56 +15,56 @@ o.spec("createText", function() {
|
|||
o("creates string", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("a")
|
||||
})
|
||||
o("creates falsy string", function() {
|
||||
var vnode = {tag: "#", children: ""}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("")
|
||||
})
|
||||
o("creates number", function() {
|
||||
var vnode = {tag: "#", children: 1}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("1")
|
||||
})
|
||||
o("creates falsy number", function() {
|
||||
var vnode = {tag: "#", children: 0}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("0")
|
||||
})
|
||||
o("creates boolean", function() {
|
||||
var vnode = {tag: "#", children: true}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("true")
|
||||
})
|
||||
o("creates falsy boolean", function() {
|
||||
var vnode = {tag: "#", children: false}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("false")
|
||||
})
|
||||
o("creates spaces", function() {
|
||||
var vnode = {tag: "#", children: " "}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals(" ")
|
||||
})
|
||||
o("ignores html", function() {
|
||||
var vnode = {tag: "#", children: "<a></a>™"}
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.nodeName).equals("#text")
|
||||
o(vnode.dom.nodeValue).equals("<a></a>™")
|
||||
})
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ o.spec("event", function() {
|
|||
var div = {tag: "div", attrs: {onclick: spy}}
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
|
||||
render(root, [div])
|
||||
div.dom.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.this).equals(div.dom)
|
||||
o(spy.args[0].type).equals("click")
|
||||
|
|
@ -40,11 +40,11 @@ o.spec("event", function() {
|
|||
var updated = {tag: "div", attrs: {id: "b", onclick: spy}}
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
|
||||
render(root, [div])
|
||||
render(root, [updated])
|
||||
div.dom.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.this).equals(div.dom)
|
||||
o(spy.args[0].type).equals("click")
|
||||
|
|
@ -62,10 +62,10 @@ o.spec("event", function() {
|
|||
var div = {tag: "div", attrs: {ontransitionend: spy}}
|
||||
var e = $window.document.createEvent("HTMLEvents")
|
||||
e.initEvent("transitionend", true, true)
|
||||
|
||||
|
||||
render(root, [div])
|
||||
div.dom.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.this).equals(div.dom)
|
||||
o(spy.args[0].type).equals("transitionend")
|
||||
|
|
@ -75,4 +75,4 @@ o.spec("event", function() {
|
|||
o(onevent.args[0].type).equals("transitionend")
|
||||
o(onevent.args[0].target).equals(div.dom)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,55 +5,55 @@ o.spec("hyperscript", function() {
|
|||
o.spec("selector", function() {
|
||||
o("handles tag in selector", function() {
|
||||
var vnode = m("a")
|
||||
|
||||
|
||||
o(vnode.tag).equals("a")
|
||||
})
|
||||
o("handles class in selector", function() {
|
||||
var vnode = m(".a")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.className).equals("a")
|
||||
})
|
||||
o("handles many classes in selector", function() {
|
||||
var vnode = m(".a.b.c")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.className).equals("a b c")
|
||||
})
|
||||
o("handles id in selector", function() {
|
||||
var vnode = m("#a")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.id).equals("a")
|
||||
})
|
||||
o("handles attr in selector", function() {
|
||||
var vnode = m("[a=b]")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
})
|
||||
o("handles many attrs in selector", function() {
|
||||
var vnode = m("[a=b][c=d]")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.attrs.c).equals("d")
|
||||
})
|
||||
o("handles attr w/ spaces in selector", function() {
|
||||
var vnode = m("[a = b]")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
})
|
||||
o("handles attr w/ quotes in selector", function() {
|
||||
var vnode = m("[a='b']")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
})
|
||||
o("handles attr w/ quoted square bracket", function() {
|
||||
var vnode = m("[x][a='[b]'].c")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.x).equals(true)
|
||||
o(vnode.attrs.a).equals("[b]")
|
||||
|
|
@ -61,55 +61,55 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles attr w/ unmatched square bracket", function() {
|
||||
var vnode = m("[a=']'].c")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("]")
|
||||
o(vnode.attrs.className).equals("c")
|
||||
})
|
||||
o("handles attr w/ quoted square bracket and quote", function() {
|
||||
var vnode = m("[a='[b\"\\']'].c") // `[a='[b"\']']`
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("[b\"']") // `[b"']`
|
||||
o(vnode.attrs.className).equals("c")
|
||||
})
|
||||
o("handles attr w/ quoted square containing escaped square bracket", function() {
|
||||
var vnode = m("[a='[\\]]'].c") // `[a='[\]]']`
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("[\\]]") // `[\]]`
|
||||
o(vnode.attrs.className).equals("c")
|
||||
})
|
||||
o("handles attr w/ backslashes", function() {
|
||||
var vnode = m("[a='\\\\'].c") // `[a='\\']`
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("\\")
|
||||
o(vnode.attrs.className).equals("c")
|
||||
})
|
||||
o("handles attr w/ quotes and spaces in selector", function() {
|
||||
var vnode = m("[a = 'b']")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
})
|
||||
o("handles many attr w/ quotes and spaces in selector", function() {
|
||||
var vnode = m("[a = 'b'][c = 'd']")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.attrs.c).equals("d")
|
||||
})
|
||||
o("handles tag, class, attrs in selector", function() {
|
||||
var vnode = m("a.b[c = 'd']")
|
||||
|
||||
|
||||
o(vnode.tag).equals("a")
|
||||
o(vnode.attrs.className).equals("b")
|
||||
o(vnode.attrs.c).equals("d")
|
||||
})
|
||||
o("handles tag, mixed classes, attrs in selector", function() {
|
||||
var vnode = m("a.b[c = 'd'].e[f = 'g']")
|
||||
|
||||
|
||||
o(vnode.tag).equals("a")
|
||||
o(vnode.attrs.className).equals("b e")
|
||||
o(vnode.attrs.c).equals("d")
|
||||
|
|
@ -117,7 +117,7 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles attr without value", function() {
|
||||
var vnode = m("[a]")
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals(true)
|
||||
})
|
||||
|
|
@ -125,102 +125,102 @@ o.spec("hyperscript", function() {
|
|||
o.spec("attrs", function() {
|
||||
o("handles string attr", function() {
|
||||
var vnode = m("div", {a: "b"})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
})
|
||||
o("handles falsy string attr", function() {
|
||||
var vnode = m("div", {a: ""})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("")
|
||||
})
|
||||
o("handles number attr", function() {
|
||||
var vnode = m("div", {a: 1})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals(1)
|
||||
})
|
||||
o("handles falsy number attr", function() {
|
||||
var vnode = m("div", {a: 0})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals(0)
|
||||
})
|
||||
o("handles boolean attr", function() {
|
||||
var vnode = m("div", {a: true})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals(true)
|
||||
})
|
||||
o("handles falsy boolean attr", function() {
|
||||
var vnode = m("div", {a: false})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals(false)
|
||||
})
|
||||
o("handles many attrs", function() {
|
||||
var vnode = m("div", {a: "b", c: "d"})
|
||||
|
||||
|
||||
o(vnode.tag).equals("div")
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.attrs.c).equals("d")
|
||||
})
|
||||
o("handles merging classes w/ class property", function() {
|
||||
var vnode = m(".a", {class: "b"})
|
||||
|
||||
|
||||
o(vnode.attrs.className).equals("a b")
|
||||
})
|
||||
o("handles merging classes w/ className property", function() {
|
||||
var vnode = m(".a", {className: "b"})
|
||||
|
||||
|
||||
o(vnode.attrs.className).equals("a b")
|
||||
})
|
||||
})
|
||||
o.spec("children", function() {
|
||||
o("handles string single child", function() {
|
||||
var vnode = m("div", {}, ["a"])
|
||||
|
||||
|
||||
o(vnode.text).equals("a")
|
||||
})
|
||||
o("handles falsy string single child", function() {
|
||||
var vnode = m("div", {}, [""])
|
||||
|
||||
|
||||
o(vnode.text).equals("")
|
||||
})
|
||||
o("handles number single child", function() {
|
||||
var vnode = m("div", {}, [1])
|
||||
|
||||
|
||||
o(vnode.text).equals(1)
|
||||
})
|
||||
o("handles falsy number single child", function() {
|
||||
var vnode = m("div", {}, [0])
|
||||
|
||||
|
||||
o(vnode.text).equals(0)
|
||||
})
|
||||
o("handles boolean single child", function() {
|
||||
var vnode = m("div", {}, [true])
|
||||
|
||||
|
||||
o(vnode.text).equals(true)
|
||||
})
|
||||
o("handles falsy boolean single child", function() {
|
||||
var vnode = m("div", {}, [false])
|
||||
|
||||
|
||||
o(vnode.text).equals(false)
|
||||
})
|
||||
o("handles null single child", function() {
|
||||
var vnode = m("div", {}, [null])
|
||||
|
||||
|
||||
o(vnode.children[0]).equals(null)
|
||||
})
|
||||
o("handles undefined single child", function() {
|
||||
var vnode = m("div", {}, [undefined])
|
||||
|
||||
|
||||
o(vnode.children[0]).equals(undefined)
|
||||
})
|
||||
o("handles multiple string children", function() {
|
||||
var vnode = m("div", {}, ["", "a"])
|
||||
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("")
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
|
|
@ -228,7 +228,7 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles multiple number children", function() {
|
||||
var vnode = m("div", {}, [0, 1])
|
||||
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(0)
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
|
|
@ -236,7 +236,7 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles multiple boolean children", function() {
|
||||
var vnode = m("div", {}, [false, true])
|
||||
|
||||
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals(false)
|
||||
o(vnode.children[1].tag).equals("#")
|
||||
|
|
@ -244,7 +244,7 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles multiple null/undefined child", function() {
|
||||
var vnode = m("div", {}, [null, undefined])
|
||||
|
||||
|
||||
o(vnode.children[0]).equals(null)
|
||||
o(vnode.children[1]).equals(undefined)
|
||||
})
|
||||
|
|
@ -252,47 +252,47 @@ o.spec("hyperscript", function() {
|
|||
o.spec("permutations", function() {
|
||||
o("handles null attr and children", function() {
|
||||
var vnode = m("div", null, [m("a"), m("b")])
|
||||
|
||||
|
||||
o(vnode.children.length).equals(2)
|
||||
o(vnode.children[0].tag).equals("a")
|
||||
o(vnode.children[1].tag).equals("b")
|
||||
})
|
||||
o("handles null attr and child unwrapped", function() {
|
||||
var vnode = m("div", null, m("a"))
|
||||
|
||||
|
||||
o(vnode.children.length).equals(1)
|
||||
o(vnode.children[0].tag).equals("a")
|
||||
})
|
||||
o("handles null attr and children unwrapped", function() {
|
||||
var vnode = m("div", null, m("a"), m("b"))
|
||||
|
||||
|
||||
o(vnode.children.length).equals(2)
|
||||
o(vnode.children[0].tag).equals("a")
|
||||
o(vnode.children[1].tag).equals("b")
|
||||
})
|
||||
o("handles attr and children", function() {
|
||||
var vnode = m("div", {a: "b"}, [m("i"), m("s")])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.children[0].tag).equals("i")
|
||||
o(vnode.children[1].tag).equals("s")
|
||||
})
|
||||
o("handles attr and child unwrapped", function() {
|
||||
var vnode = m("div", {a: "b"}, m("i"))
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.children[0].tag).equals("i")
|
||||
})
|
||||
o("handles attr and children unwrapped", function() {
|
||||
var vnode = m("div", {a: "b"}, m("i"), m("s"))
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.children[0].tag).equals("i")
|
||||
o(vnode.children[1].tag).equals("s")
|
||||
})
|
||||
o("handles attr and text children", function() {
|
||||
var vnode = m("div", {a: "b"}, ["c", "d"])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("c")
|
||||
|
|
@ -301,49 +301,49 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles attr and single string text child", function() {
|
||||
var vnode = m("div", {a: "b"}, ["c"])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals("c")
|
||||
})
|
||||
o("handles attr and single falsy string text child", function() {
|
||||
var vnode = m("div", {a: "b"}, [""])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals("")
|
||||
})
|
||||
o("handles attr and single number text child", function() {
|
||||
var vnode = m("div", {a: "b"}, [1])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals(1)
|
||||
})
|
||||
o("handles attr and single falsy number text child", function() {
|
||||
var vnode = m("div", {a: "b"}, [0])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals(0)
|
||||
})
|
||||
o("handles attr and single boolean text child", function() {
|
||||
var vnode = m("div", {a: "b"}, [true])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals(true)
|
||||
})
|
||||
o("handles attr and single falsy boolean text child", function() {
|
||||
var vnode = m("div", {a: "b"}, [false])
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals(false)
|
||||
})
|
||||
o("handles attr and single text child unwrapped", function() {
|
||||
var vnode = m("div", {a: "b"}, "c")
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.text).equals("c")
|
||||
})
|
||||
o("handles attr and text children unwrapped", function() {
|
||||
var vnode = m("div", {a: "b"}, "c", "d")
|
||||
|
||||
|
||||
o(vnode.attrs.a).equals("b")
|
||||
o(vnode.children[0].tag).equals("#")
|
||||
o(vnode.children[0].children).equals("c")
|
||||
|
|
@ -352,27 +352,27 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles children without attr", function() {
|
||||
var vnode = m("div", [m("i"), m("s")])
|
||||
|
||||
|
||||
o(vnode.attrs).equals(undefined)
|
||||
o(vnode.children[0].tag).equals("i")
|
||||
o(vnode.children[1].tag).equals("s")
|
||||
})
|
||||
o("handles child without attr unwrapped", function() {
|
||||
var vnode = m("div", m("i"))
|
||||
|
||||
|
||||
o(vnode.attrs).equals(undefined)
|
||||
o(vnode.children[0].tag).equals("i")
|
||||
})
|
||||
o("handles children without attr unwrapped", function() {
|
||||
var vnode = m("div", m("i"), m("s"))
|
||||
|
||||
|
||||
o(vnode.attrs).equals(undefined)
|
||||
o(vnode.children[0].tag).equals("i")
|
||||
o(vnode.children[1].tag).equals("s")
|
||||
})
|
||||
o("handles fragment children without attr unwrapped", function() {
|
||||
var vnode = m("div", [m("i")], [m("s")])
|
||||
|
||||
|
||||
o(vnode.children[0].tag).equals("[")
|
||||
o(vnode.children[0].children[0].tag).equals("i")
|
||||
o(vnode.children[1].tag).equals("[")
|
||||
|
|
@ -380,14 +380,14 @@ o.spec("hyperscript", function() {
|
|||
})
|
||||
o("handles children with nested array", function() {
|
||||
var vnode = m("div", [[m("i"), m("s")]])
|
||||
|
||||
|
||||
o(vnode.children[0].tag).equals("[")
|
||||
o(vnode.children[0].children[0].tag).equals("i")
|
||||
o(vnode.children[0].children[1].tag).equals("s")
|
||||
})
|
||||
o("handles children with deeply nested array", function() {
|
||||
var vnode = m("div", [[[m("i"), m("s")]]])
|
||||
|
||||
|
||||
o(vnode.children[0].tag).equals("[")
|
||||
o(vnode.children[0].children[0].tag).equals("[")
|
||||
o(vnode.children[0].children[0].children[0].tag).equals("i")
|
||||
|
|
@ -402,7 +402,7 @@ o.spec("hyperscript", function() {
|
|||
}
|
||||
}
|
||||
var vnode = m(component, {id: "a"}, "b")
|
||||
|
||||
|
||||
o(vnode.tag).equals(component)
|
||||
o(vnode.attrs.id).equals("a")
|
||||
o(vnode.children.length).equals(1)
|
||||
|
|
@ -410,4 +410,4 @@ o.spec("hyperscript", function() {
|
|||
o(vnode.children[0].children).equals("b")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -22,86 +22,86 @@ o.spec("form inputs", function() {
|
|||
var input = {tag: "input", key: 1}
|
||||
var a = {tag: "a", key: 2}
|
||||
var b = {tag: "b", key: 3}
|
||||
|
||||
|
||||
render(root, [input, a, b])
|
||||
input.dom.focus()
|
||||
render(root, [a, input, b])
|
||||
|
||||
|
||||
o($window.document.activeElement).equals(input.dom)
|
||||
})
|
||||
|
||||
|
||||
o("syncs input value if DOM value differs from vdom value", function() {
|
||||
var input = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
||||
var updated = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
||||
|
||||
|
||||
render(root, [input])
|
||||
|
||||
|
||||
//simulate user typing
|
||||
var e = $window.document.createEvent("KeyboardEvent")
|
||||
e.initEvent("input", true, true)
|
||||
input.dom.focus()
|
||||
input.dom.value += "a"
|
||||
input.dom.dispatchEvent(e)
|
||||
|
||||
|
||||
//re-render may use same vdom value as previous render call
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.value).equals("aaa")
|
||||
})
|
||||
|
||||
|
||||
o("syncs input checked attribute if DOM value differs from vdom value", function() {
|
||||
var input = {tag: "input", attrs: {type: "checkbox", checked: true, onclick: function() {}}}
|
||||
var updated = {tag: "input", attrs: {type: "checkbox", checked: true, onclick: function() {}}}
|
||||
|
||||
|
||||
render(root, [input])
|
||||
|
||||
|
||||
//simulate user clicking checkbox
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
input.dom.focus()
|
||||
input.dom.dispatchEvent(e)
|
||||
|
||||
|
||||
//re-render may use same vdom value as previous render call
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.checked).equals(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("select", function() {
|
||||
o("select works without attributes", function() {
|
||||
var select = {tag: "select", children: [
|
||||
{tag: "option", attrs: {value: "a"}, text: "aaa"},
|
||||
]}
|
||||
|
||||
|
||||
render(root, [select])
|
||||
|
||||
|
||||
o(select.dom.value).equals("a")
|
||||
o(select.dom.selectedIndex).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("select yields invalid value without children", function() {
|
||||
var select = {tag: "select", attrs: {value: "a"}}
|
||||
|
||||
|
||||
render(root, [select])
|
||||
|
||||
|
||||
o(select.dom.value).equals("")
|
||||
o(select.dom.selectedIndex).equals(-1)
|
||||
})
|
||||
|
||||
|
||||
o("select value is set correctly on first render", function() {
|
||||
var select = {tag: "select", attrs: {value: "b"}, children: [
|
||||
{tag: "option", attrs: {value: "a"}, text: "aaa"},
|
||||
{tag: "option", attrs: {value: "b"}, text: "bbb"},
|
||||
{tag: "option", attrs: {value: "c"}, text: "ccc"},
|
||||
]}
|
||||
|
||||
|
||||
render(root, [select])
|
||||
|
||||
|
||||
o(select.dom.value).equals("b")
|
||||
o(select.dom.selectedIndex).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("syncs select value if DOM value differs from vdom value", function() {
|
||||
function makeSelect() {
|
||||
return {tag: "select", attrs: {value: "b"}, children: [
|
||||
|
|
@ -110,33 +110,33 @@ o.spec("form inputs", function() {
|
|||
{tag: "option", attrs: {value: "c"}, text: "ccc"},
|
||||
]}
|
||||
}
|
||||
|
||||
|
||||
render(root, [makeSelect()])
|
||||
|
||||
|
||||
//simulate user selecting option
|
||||
root.firstChild.value = "c"
|
||||
root.firstChild.focus()
|
||||
|
||||
|
||||
//re-render may use same vdom value as previous render call
|
||||
render(root, [makeSelect()])
|
||||
|
||||
|
||||
o(root.firstChild.value).equals("b")
|
||||
o(root.firstChild.selectedIndex).equals(1)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("textarea", function() {
|
||||
o("updates after user input", function() {
|
||||
render(root, [{tag: "textarea", text: "aaa"}])
|
||||
|
||||
|
||||
//simulate typing
|
||||
root.firstChild.value = "bbb"
|
||||
|
||||
|
||||
//re-render may occur after value attribute is touched
|
||||
render(root, [{tag: "textarea", text: "ccc"}])
|
||||
|
||||
|
||||
o(root.firstChild.value).equals("ccc")
|
||||
//FIXME should fail if fix is commented out
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ var Node = require("../../render/node")
|
|||
o.spec("normalize", function() {
|
||||
o("normalizes array into fragment", function() {
|
||||
var node = Node.normalize([])
|
||||
|
||||
|
||||
o(node.tag).equals("[")
|
||||
o(node.children.length).equals(0)
|
||||
})
|
||||
o("normalizes nested array into fragment", function() {
|
||||
var node = Node.normalize([[]])
|
||||
|
||||
|
||||
o(node.tag).equals("[")
|
||||
o(node.children.length).equals(1)
|
||||
o(node.children[0].tag).equals("[")
|
||||
|
|
@ -20,39 +20,38 @@ o.spec("normalize", function() {
|
|||
})
|
||||
o("normalizes string into text node", function() {
|
||||
var node = Node.normalize("a")
|
||||
|
||||
|
||||
o(node.tag).equals("#")
|
||||
o(node.children).equals("a")
|
||||
})
|
||||
o("normalizes falsy string into text node", function() {
|
||||
var node = Node.normalize("")
|
||||
|
||||
|
||||
o(node.tag).equals("#")
|
||||
o(node.children).equals("")
|
||||
})
|
||||
o("normalizes number into text node", function() {
|
||||
var node = Node.normalize(1)
|
||||
|
||||
|
||||
o(node.tag).equals("#")
|
||||
o(node.children).equals(1)
|
||||
})
|
||||
o("normalizes falsy number into text node", function() {
|
||||
var node = Node.normalize(0)
|
||||
|
||||
|
||||
o(node.tag).equals("#")
|
||||
o(node.children).equals(0)
|
||||
})
|
||||
o("normalizes boolean into text node", function() {
|
||||
var node = Node.normalize(true)
|
||||
|
||||
|
||||
o(node.tag).equals("#")
|
||||
o(node.children).equals(true)
|
||||
})
|
||||
o("normalizes falsy boolean into text node", function() {
|
||||
var node = Node.normalize(false)
|
||||
|
||||
|
||||
o(node.tag).equals("#")
|
||||
o(node.children).equals(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -6,15 +6,14 @@ var Node = require("../../render/node")
|
|||
o.spec("normalizeChildren", function() {
|
||||
o("normalizes arrays into fragments", function() {
|
||||
var children = Node.normalizeChildren([[]])
|
||||
|
||||
|
||||
o(children[0].tag).equals("[")
|
||||
o(children[0].children.length).equals(0)
|
||||
})
|
||||
o("normalizes strings into text nodes", function() {
|
||||
var children = Node.normalizeChildren(["a"])
|
||||
|
||||
|
||||
o(children[0].tag).equals("#")
|
||||
o(children[0].children).equals("a")
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ o.spec("onbeforeremove", function() {
|
|||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
})
|
||||
o("does not call onbeforeremove when updating", function() {
|
||||
|
|
@ -27,29 +27,29 @@ o.spec("onbeforeremove", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
||||
var updated = {tag: "div", attrs: {onbeforeremove: update}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("calls onbeforeremove when removing element", function(done) {
|
||||
var vnode = {tag: "div", attrs: {onbeforeremove: remove}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
function remove(node, complete) {
|
||||
o(node).equals(vnode)
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(vnode.dom)
|
||||
|
||||
|
||||
callAsync(function() {
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
||||
|
||||
complete()
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -58,20 +58,20 @@ o.spec("onbeforeremove", function() {
|
|||
})
|
||||
o("calls onbeforeremove when removing text", function(done) {
|
||||
var vnode = {tag: "#", attrs: {onbeforeremove: remove}, children: "a"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
function remove(node, complete) {
|
||||
o(node).equals(vnode)
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(vnode.dom)
|
||||
|
||||
|
||||
callAsync(function() {
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
||||
|
||||
complete()
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -80,20 +80,20 @@ o.spec("onbeforeremove", function() {
|
|||
})
|
||||
o("calls onbeforeremove when removing fragment", function(done) {
|
||||
var vnode = {tag: "[", attrs: {onbeforeremove: remove}, children: [{tag: "div"}]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
function remove(node, complete) {
|
||||
o(node).equals(vnode)
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(vnode.dom)
|
||||
|
||||
|
||||
callAsync(function() {
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
||||
|
||||
complete()
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -102,20 +102,20 @@ o.spec("onbeforeremove", function() {
|
|||
})
|
||||
o("calls onbeforeremove when removing html", function(done) {
|
||||
var vnode = {tag: "<", attrs: {onbeforeremove: remove}, children: "a"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
function remove(node, complete) {
|
||||
o(node).equals(vnode)
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(vnode.dom)
|
||||
|
||||
|
||||
callAsync(function() {
|
||||
o(root.childNodes.length).equals(1)
|
||||
|
||||
|
||||
complete()
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -125,21 +125,21 @@ o.spec("onbeforeremove", function() {
|
|||
o("calls remove after onbeforeremove resolves", function(done) {
|
||||
var spy = o.spy()
|
||||
var vnode = {tag: "<", attrs: {onbeforeremove: remove, onremove: spy}, children: "a"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
function remove(node, complete) {
|
||||
o(node).equals(vnode)
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild).equals(vnode.dom)
|
||||
|
||||
|
||||
callAsync(function() {
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(spy.callCount).equals(0)
|
||||
|
||||
|
||||
complete()
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(0)
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
|
|
@ -150,9 +150,9 @@ o.spec("onbeforeremove", function() {
|
|||
o("does not set onbeforeremove as an event handler", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onbeforeremove: remove}, children: []}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.onbeforeremove).equals(undefined)
|
||||
o(vnode.dom.attributes["onbeforeremove"]).equals(undefined)
|
||||
})
|
||||
|
|
@ -160,11 +160,11 @@ o.spec("onbeforeremove", function() {
|
|||
var remove = function(vnode, done) {done()}
|
||||
var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -11,51 +11,51 @@ o.spec("onbeforeupdate", function() {
|
|||
root = $window.document.createElement("div")
|
||||
render = vdom($window).render
|
||||
})
|
||||
|
||||
|
||||
o("prevents update in element", function() {
|
||||
var onbeforeupdate = function() {return false}
|
||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
})
|
||||
|
||||
|
||||
o("prevents update in text", function() {
|
||||
var onbeforeupdate = function() {return false}
|
||||
var vnode = {tag: "#", attrs: {onbeforeupdate: onbeforeupdate}, children: "a"}
|
||||
var updated = {tag: "#", attrs: {onbeforeupdate: onbeforeupdate}, children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.nodeValue).equals("a")
|
||||
})
|
||||
|
||||
|
||||
o("prevents update in html", function() {
|
||||
var onbeforeupdate = function() {return false}
|
||||
var vnode = {tag: "<", attrs: {onbeforeupdate: onbeforeupdate}, children: "a"}
|
||||
var updated = {tag: "<", attrs: {onbeforeupdate: onbeforeupdate}, children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.nodeValue).equals("a")
|
||||
})
|
||||
|
||||
|
||||
o("prevents update in fragment", function() {
|
||||
var onbeforeupdate = function() {return false}
|
||||
var vnode = {tag: "[", attrs: {onbeforeupdate: onbeforeupdate}, children: [{tag: "#", children: "a"}]}
|
||||
var updated = {tag: "[", attrs: {onbeforeupdate: onbeforeupdate}, children: [{tag: "#", children: "b"}]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.nodeValue).equals("a")
|
||||
})
|
||||
|
||||
|
||||
o("prevents update in component", function() {
|
||||
var component = {
|
||||
onbeforeupdate: function() {return false},
|
||||
|
|
@ -65,13 +65,13 @@ o.spec("onbeforeupdate", function() {
|
|||
}
|
||||
var vnode = {tag: component, children: [{tag: "#", children: "a"}]}
|
||||
var updated = {tag: component, children: [{tag: "#", children: "b"}]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.firstChild.nodeValue).equals("a")
|
||||
})
|
||||
|
||||
|
||||
o("prevents update if returning false in component and false in vnode", function() {
|
||||
var component = {
|
||||
onbeforeupdate: function() {return false},
|
||||
|
|
@ -81,13 +81,13 @@ o.spec("onbeforeupdate", function() {
|
|||
}
|
||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}}
|
||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||
})
|
||||
|
||||
|
||||
o("does not prevent update if returning true in component and true in vnode", function() {
|
||||
var component = {
|
||||
onbeforeupdate: function() {return true},
|
||||
|
|
@ -97,13 +97,13 @@ o.spec("onbeforeupdate", function() {
|
|||
}
|
||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}}
|
||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("does not prevent update if returning false in component but true in vnode", function() {
|
||||
var component = {
|
||||
onbeforeupdate: function() {return false},
|
||||
|
|
@ -113,13 +113,13 @@ o.spec("onbeforeupdate", function() {
|
|||
}
|
||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}}
|
||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("does not prevent update if returning true in component but false in vnode", function() {
|
||||
var component = {
|
||||
onbeforeupdate: function() {return true},
|
||||
|
|
@ -129,24 +129,24 @@ o.spec("onbeforeupdate", function() {
|
|||
}
|
||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}}
|
||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("does not prevent update if returning true", function() {
|
||||
var onbeforeupdate = function() {return true}
|
||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("does not prevent update if returning true from component", function() {
|
||||
var component = {
|
||||
onbeforeupdate: function() {return true},
|
||||
|
|
@ -156,34 +156,34 @@ o.spec("onbeforeupdate", function() {
|
|||
}
|
||||
var vnode = {tag: component, attrs: {id: "a"}}
|
||||
var updated = {tag: component, attrs: {id: "b"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("accepts arguments for comparison", function() {
|
||||
var count = 0
|
||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
function onbeforeupdate(vnode, old) {
|
||||
count++
|
||||
|
||||
|
||||
o(old.attrs.id).equals("a")
|
||||
o(vnode.attrs.id).equals("b")
|
||||
|
||||
|
||||
return old.attrs.id !== vnode.attrs.id
|
||||
}
|
||||
|
||||
|
||||
o(count).equals(1)
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("accepts arguments for comparison in component", function() {
|
||||
var component = {
|
||||
onbeforeupdate: onbeforeupdate,
|
||||
|
|
@ -194,38 +194,38 @@ o.spec("onbeforeupdate", function() {
|
|||
var count = 0
|
||||
var vnode = {tag: component, attrs: {id: "a"}}
|
||||
var updated = {tag: component, attrs: {id: "b"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
function onbeforeupdate(vnode, old) {
|
||||
count++
|
||||
|
||||
|
||||
o(old.attrs.id).equals("a")
|
||||
o(vnode.attrs.id).equals("b")
|
||||
|
||||
|
||||
return old.attrs.id !== vnode.attrs.id
|
||||
}
|
||||
|
||||
|
||||
o(count).equals(1)
|
||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||
})
|
||||
|
||||
|
||||
o("is not called on creation", function() {
|
||||
var count = 0
|
||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
function onbeforeupdate(vnode, old) {
|
||||
count++
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
o(count).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("is not called on component creation", function() {
|
||||
var component = {
|
||||
onbeforeupdate: onbeforeupdate,
|
||||
|
|
@ -233,37 +233,37 @@ o.spec("onbeforeupdate", function() {
|
|||
return {tag: "div", attrs: vnode.attrs}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var count = 0
|
||||
var vnode = {tag: "div", attrs: {id: "a"}}
|
||||
var updated = {tag: "div", attrs: {id: "b"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
function onbeforeupdate(vnode, old) {
|
||||
count++
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
o(count).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("is called only once on update", function() {
|
||||
var count = 0
|
||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
function onbeforeupdate(vnode, old) {
|
||||
count++
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
o(count).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("is called only once on component update", function() {
|
||||
var component = {
|
||||
onbeforeupdate: onbeforeupdate,
|
||||
|
|
@ -271,19 +271,19 @@ o.spec("onbeforeupdate", function() {
|
|||
return {tag: "div", attrs: vnode.attrs}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var count = 0
|
||||
var vnode = {tag: component, attrs: {id: "a"}}
|
||||
var updated = {tag: component, attrs: {id: "b"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
function onbeforeupdate(vnode, old) {
|
||||
count++
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
o(count).equals(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ o.spec("oncreate", function() {
|
|||
o("calls oncreate when creating element", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: callback}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -25,9 +25,9 @@ o.spec("oncreate", function() {
|
|||
o("calls oncreate when creating text", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "#", attrs: {oncreate: callback}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -35,9 +35,9 @@ o.spec("oncreate", function() {
|
|||
o("calls oncreate when creating fragment", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "[", attrs: {oncreate: callback}, children: [], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -45,9 +45,9 @@ o.spec("oncreate", function() {
|
|||
o("calls oncreate when creating html", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "<", attrs: {oncreate: callback}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -57,10 +57,10 @@ o.spec("oncreate", function() {
|
|||
var createA = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: createDiv}, state: {}}
|
||||
var updated = {tag: "a", key: 1, attrs: {oncreate: createA}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(createDiv.callCount).equals(1)
|
||||
o(createDiv.this).equals(vnode.state)
|
||||
o(createDiv.args[0]).equals(vnode)
|
||||
|
|
@ -73,10 +73,10 @@ o.spec("oncreate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -87,10 +87,10 @@ o.spec("oncreate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update, id: "a"}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -101,10 +101,10 @@ o.spec("oncreate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update}, children: [{tag: "b"}], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -117,10 +117,10 @@ o.spec("oncreate", function() {
|
|||
var otherVnode = {tag: "a", key: 2}
|
||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
||||
var otherUpdated = {tag: "a", key: 2}
|
||||
|
||||
|
||||
render(root, [vnode, otherVnode])
|
||||
render(root, [otherUpdated, updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -130,10 +130,10 @@ o.spec("oncreate", function() {
|
|||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -143,11 +143,11 @@ o.spec("oncreate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}, state: {}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
|
|
@ -162,10 +162,10 @@ o.spec("oncreate", function() {
|
|||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oncreate: callback}, state: {}}], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -181,12 +181,12 @@ o.spec("oncreate", function() {
|
|||
{tag: "b"}
|
||||
]}
|
||||
]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
function create(vnode) {
|
||||
created = true
|
||||
|
||||
|
||||
o(vnode.dom.parentNode).notEquals(null)
|
||||
o(vnode.dom.childNodes.length).equals(1)
|
||||
}
|
||||
|
|
@ -195,9 +195,9 @@ o.spec("oncreate", function() {
|
|||
o("does not set oncreate as an event handler", function() {
|
||||
var create = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, children: []}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.oncreate).equals(undefined)
|
||||
o(vnode.dom.attributes["oncreate"]).equals(undefined)
|
||||
})
|
||||
|
|
@ -206,11 +206,11 @@ o.spec("oncreate", function() {
|
|||
var vnodes = [{tag: "div", key: 1, attrs: {oncreate: create}}]
|
||||
var temp = []
|
||||
var updated = [{tag: "div", key: 1, attrs: {oncreate: create}}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(create.callCount).equals(2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ o.spec("oninit", function() {
|
|||
o("calls oninit when creating element", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: callback}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -25,9 +25,9 @@ o.spec("oninit", function() {
|
|||
o("calls oninit when creating text", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "#", attrs: {oninit: callback}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -35,9 +35,9 @@ o.spec("oninit", function() {
|
|||
o("calls oninit when creating fragment", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "[", attrs: {oninit: callback}, children: [], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -45,9 +45,9 @@ o.spec("oninit", function() {
|
|||
o("calls oninit when creating html", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "<", attrs: {oninit: callback}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
|
|
@ -57,10 +57,10 @@ o.spec("oninit", function() {
|
|||
var createA = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: createDiv}, state: {}}
|
||||
var updated = {tag: "a", key: 1, attrs: {oninit: createA}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(createDiv.callCount).equals(1)
|
||||
o(createDiv.this).equals(vnode.state)
|
||||
o(createDiv.args[0]).equals(vnode)
|
||||
|
|
@ -73,10 +73,10 @@ o.spec("oninit", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oninit: update}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -87,10 +87,10 @@ o.spec("oninit", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oninit: update, id: "a"}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -101,10 +101,10 @@ o.spec("oninit", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {oninit: update}, children: [{tag: "b"}], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -117,10 +117,10 @@ o.spec("oninit", function() {
|
|||
var otherVnode = {tag: "a", key: 2}
|
||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
||||
var otherUpdated = {tag: "a", key: 2}
|
||||
|
||||
|
||||
render(root, [vnode, otherVnode])
|
||||
render(root, [otherUpdated, updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -130,10 +130,10 @@ o.spec("oninit", function() {
|
|||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
|
|
@ -143,11 +143,11 @@ o.spec("oninit", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: create}, state: {}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(vnode.dom).equals(updated.dom)
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
|
|
@ -162,10 +162,10 @@ o.spec("oninit", function() {
|
|||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oninit: callback}, state: {}}], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -181,12 +181,12 @@ o.spec("oninit", function() {
|
|||
{tag: "b"}
|
||||
]}
|
||||
]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
function create(vnode) {
|
||||
called = true
|
||||
|
||||
|
||||
o(vnode.dom).equals(undefined)
|
||||
o(root.childNodes.length).equals(0)
|
||||
}
|
||||
|
|
@ -195,9 +195,9 @@ o.spec("oninit", function() {
|
|||
o("does not set oninit as an event handler", function() {
|
||||
var create = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, children: []}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.oninit).equals(undefined)
|
||||
o(vnode.dom.attributes["oninit"]).equals(undefined)
|
||||
})
|
||||
|
|
@ -206,11 +206,11 @@ o.spec("oninit", function() {
|
|||
var vnodes = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
||||
var temp = []
|
||||
var updated = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(create.callCount).equals(2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ o.spec("onremove", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onremove: create}}
|
||||
var updated = {tag: "div", attrs: {onremove: update}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
})
|
||||
o("does not call onremove when updating", function() {
|
||||
|
|
@ -28,20 +28,20 @@ o.spec("onremove", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onremove: create}}
|
||||
var updated = {tag: "div", attrs: {onremove: update}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("calls onremove when removing element", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onremove: remove}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
|
|
@ -49,10 +49,10 @@ o.spec("onremove", function() {
|
|||
o("calls onremove when removing text", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "#", attrs: {onremove: remove}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
|
|
@ -60,10 +60,10 @@ o.spec("onremove", function() {
|
|||
o("calls onremove when removing fragment", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "[", attrs: {onremove: remove}, children: [], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
|
|
@ -71,10 +71,10 @@ o.spec("onremove", function() {
|
|||
o("calls onremove when removing html", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "<", attrs: {onremove: remove}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
|
|
@ -82,9 +82,9 @@ o.spec("onremove", function() {
|
|||
o("does not set onremove as an event handler", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onremove: remove}, children: []}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.onremove).equals(undefined)
|
||||
o(vnode.dom.attributes["onremove"]).equals(undefined)
|
||||
})
|
||||
|
|
@ -93,22 +93,22 @@ o.spec("onremove", function() {
|
|||
var vnodes = [{tag: "div", key: 1}]
|
||||
var temp = [{tag: "div", key: 2, attrs: {onremove: remove}}]
|
||||
var updated = [{tag: "div", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
})
|
||||
o("does not recycle when there's an onremove", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {onremove: remove}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onremove: remove}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -29,10 +29,10 @@ o.spec("onupdate", function() {
|
|||
o("does not call onupdate when removing element", function() {
|
||||
var create = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
})
|
||||
o("does not call onupdate when replacing keyed element", function() {
|
||||
|
|
@ -42,7 +42,7 @@ o.spec("onupdate", function() {
|
|||
var updated = {tag: "a", key: 1, attrs: {onupdate: update}}
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
|
|
@ -50,11 +50,11 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
||||
|
|
@ -62,10 +62,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "a", attrs: {onupdate: create}}
|
||||
var updated = {tag: "a"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
})
|
||||
o("calls onupdate when noop", function() {
|
||||
|
|
@ -73,10 +73,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -87,10 +87,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update, id: "a"}, state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -101,10 +101,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "b"}], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -115,10 +115,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "#", attrs: {onupdate: create}, children: "a", state: {}}
|
||||
var updated = {tag: "#", attrs: {onupdate: update}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -129,10 +129,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "[", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "[", attrs: {onupdate: update}, children: [], state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -143,10 +143,10 @@ o.spec("onupdate", function() {
|
|||
var update = o.spy()
|
||||
var vnode = {tag: "<", attrs: {onupdate: create}, children: "a", state: {}}
|
||||
var updated = {tag: "<", attrs: {onupdate: update}, children: "a", state: {}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
|
|
@ -164,13 +164,13 @@ o.spec("onupdate", function() {
|
|||
{tag: "b", attrs: {id: "33"}}
|
||||
]}
|
||||
]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
function update(vnode) {
|
||||
called = true
|
||||
|
||||
|
||||
o(vnode.dom.parentNode.attributes["id"].nodeValue).equals("11")
|
||||
o(vnode.dom.attributes["id"].nodeValue).equals("22")
|
||||
o(vnode.dom.childNodes[0].attributes["id"].nodeValue).equals("33")
|
||||
|
|
@ -180,10 +180,10 @@ o.spec("onupdate", function() {
|
|||
o("does not set onupdate as an event handler", function() {
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: update}, children: []}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
o(vnode.dom.onupdate).equals(undefined)
|
||||
o(vnode.dom.attributes["onupdate"]).equals(undefined)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,27 +14,27 @@ o.spec("textContent", function() {
|
|||
|
||||
o("ignores null", function() {
|
||||
var vnodes = [{tag: "a", text: null}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(0)
|
||||
o(vnodes[0].dom).equals(root.childNodes[0])
|
||||
})
|
||||
o("ignores undefined", function() {
|
||||
var vnodes = [{tag: "a", text: undefined}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(0)
|
||||
o(vnodes[0].dom).equals(root.childNodes[0])
|
||||
})
|
||||
o("creates string", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("a")
|
||||
|
|
@ -42,9 +42,9 @@ o.spec("textContent", function() {
|
|||
})
|
||||
o("creates falsy string", function() {
|
||||
var vnodes = [{tag: "a", text: ""}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
||||
|
|
@ -52,9 +52,9 @@ o.spec("textContent", function() {
|
|||
})
|
||||
o("creates number", function() {
|
||||
var vnodes = [{tag: "a", text: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
||||
|
|
@ -62,9 +62,9 @@ o.spec("textContent", function() {
|
|||
})
|
||||
o("creates falsy number", function() {
|
||||
var vnodes = [{tag: "a", text: 0}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
||||
|
|
@ -72,9 +72,9 @@ o.spec("textContent", function() {
|
|||
})
|
||||
o("creates boolean", function() {
|
||||
var vnodes = [{tag: "a", text: true}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
||||
|
|
@ -82,9 +82,9 @@ o.spec("textContent", function() {
|
|||
})
|
||||
o("creates falsy boolean", function() {
|
||||
var vnodes = [{tag: "a", text: false}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
||||
|
|
@ -93,10 +93,10 @@ o.spec("textContent", function() {
|
|||
o("updates to string", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a", text: "b"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
||||
|
|
@ -105,10 +105,10 @@ o.spec("textContent", function() {
|
|||
o("updates to falsy string", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a", text: ""}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
||||
|
|
@ -117,10 +117,10 @@ o.spec("textContent", function() {
|
|||
o("updates to number", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a", text: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
||||
|
|
@ -129,10 +129,10 @@ o.spec("textContent", function() {
|
|||
o("updates to falsy number", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a", text: 0}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
||||
|
|
@ -141,10 +141,10 @@ o.spec("textContent", function() {
|
|||
o("updates to boolean", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a", text: true}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
||||
|
|
@ -153,10 +153,10 @@ o.spec("textContent", function() {
|
|||
o("updates to falsy boolean", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a", text: false}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
||||
|
|
@ -165,10 +165,10 @@ o.spec("textContent", function() {
|
|||
o("updates with typecasting", function() {
|
||||
var vnodes = [{tag: "a", text: "1"}]
|
||||
var updated = [{tag: "a", text: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
||||
|
|
@ -177,10 +177,10 @@ o.spec("textContent", function() {
|
|||
o("updates from without text to with text", function() {
|
||||
var vnodes = [{tag: "a"}]
|
||||
var updated = [{tag: "a", text: "b"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
||||
|
|
@ -189,12 +189,12 @@ o.spec("textContent", function() {
|
|||
o("updates from with text to without text", function() {
|
||||
var vnodes = [{tag: "a", text: "a"}]
|
||||
var updated = [{tag: "a"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(vnodes[0].dom.childNodes.length).equals(0)
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ var trust = require("../../render/trust")
|
|||
o.spec("trust", function() {
|
||||
o("works with html", function() {
|
||||
var vnode = trust("<a></a>")
|
||||
|
||||
|
||||
o(vnode.tag).equals("<")
|
||||
o(vnode.children).equals("<a></a>")
|
||||
})
|
||||
o("works with text", function() {
|
||||
var vnode = trust("abc")
|
||||
|
||||
|
||||
o(vnode.tag).equals("<")
|
||||
o(vnode.children).equals("abc")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ o.spec("updateElement", function() {
|
|||
o("updates attr", function() {
|
||||
var vnode = {tag: "a", attrs: {id: "b"}}
|
||||
var updated = {tag: "a", attrs: {id: "c"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.attributes["id"].nodeValue).equals("c")
|
||||
|
|
@ -26,10 +26,10 @@ o.spec("updateElement", function() {
|
|||
o("adds attr", function() {
|
||||
var vnode = {tag: "a", attrs: {id: "b"}}
|
||||
var updated = {tag: "a", attrs: {id: "c", title: "d"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.attributes["title"].nodeValue).equals("d")
|
||||
|
|
@ -37,10 +37,10 @@ o.spec("updateElement", function() {
|
|||
o("adds attr from empty attrs", function() {
|
||||
var vnode = {tag: "a"}
|
||||
var updated = {tag: "a", attrs: {title: "d"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.attributes["title"].nodeValue).equals("d")
|
||||
|
|
@ -48,10 +48,10 @@ o.spec("updateElement", function() {
|
|||
o("removes attr", function() {
|
||||
var vnode = {tag: "a", attrs: {id: "b", title: "d"}}
|
||||
var updated = {tag: "a", attrs: {id: "c"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o("title" in updated.dom.attributes).equals(false)
|
||||
|
|
@ -59,145 +59,145 @@ o.spec("updateElement", function() {
|
|||
o("creates style object", function() {
|
||||
var vnode = {tag: "a", attrs: {}}
|
||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("creates style string", function() {
|
||||
var vnode = {tag: "a", attrs: {}}
|
||||
var updated = {tag: "a", attrs: {style: "background-color:green"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("updates style from object to object", function() {
|
||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("updates style from object to string", function() {
|
||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("handles noop style change when style is string", function() {
|
||||
var vnode = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("handles noop style change when style is object", function() {
|
||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("red")
|
||||
})
|
||||
o("updates style from string to object", function() {
|
||||
var vnode = {tag: "a", attrs: {style: "background-color:red;"}}
|
||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("updates style from string to string", function() {
|
||||
var vnode = {tag: "a", attrs: {style: "background-color:red;"}}
|
||||
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("green")
|
||||
})
|
||||
o("removes style from object to object", function() {
|
||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red", border: "1px solid red"}}}
|
||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("red")
|
||||
o(updated.dom.style.border).equals("")
|
||||
})
|
||||
o("removes style from string to object", function() {
|
||||
var vnode = {tag: "a", attrs: {style: "background-color:red;border:1px solid red"}}
|
||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("red")
|
||||
o(updated.dom.style.border).notEquals("1px solid red")
|
||||
})
|
||||
o("removes style from object to string", function() {
|
||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red", border: "1px solid red"}}}
|
||||
var updated = {tag: "a", attrs: {style: "background-color:red"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("red")
|
||||
o(updated.dom.style.border).equals("")
|
||||
})
|
||||
o("removes style from string to string", function() {
|
||||
var vnode = {tag: "a", attrs: {style: "background-color:red;border:1px solid red"}}
|
||||
var updated = {tag: "a", attrs: {style: "background-color:red"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("red")
|
||||
o(updated.dom.style.border).equals("")
|
||||
})
|
||||
o("updates style when it's same object but mutated", function() {
|
||||
var style = {backgroundColor: "red", color: "gold"}
|
||||
var vnode = {tag: "a", attrs: {style: style}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
|
||||
delete style.backgroundColor
|
||||
var updated = {tag: "a", attrs: {style: style}}
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.style.backgroundColor).equals("")
|
||||
o(updated.dom.style.color).equals("gold")
|
||||
})
|
||||
o("replaces el", function() {
|
||||
var vnode = {tag: "a"}
|
||||
var updated = {tag: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeName).equals("B")
|
||||
})
|
||||
o("updates svg class", function() {
|
||||
var vnode = {tag: "svg", attrs: {className: "a"}}
|
||||
var updated = {tag: "svg", attrs: {className: "b"}}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom.attributes["class"].nodeValue).equals("b")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,20 +15,20 @@ o.spec("updateFragment", function() {
|
|||
o("updates fragment", function() {
|
||||
var vnode = {tag: "[", children: [{tag: "a"}]}
|
||||
var updated = {tag: "[", children: [{tag: "b"}]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeName).equals("B")
|
||||
})
|
||||
o("adds els", function() {
|
||||
var vnode = {tag: "[", children: []}
|
||||
var updated = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.domSize).equals(2)
|
||||
o(root.childNodes.length).equals(2)
|
||||
|
|
@ -38,10 +38,10 @@ o.spec("updateFragment", function() {
|
|||
o("removes els", function() {
|
||||
var vnode = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
||||
var updated = {tag: "[", children: []}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(null)
|
||||
o(updated.domSize).equals(0)
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
|
@ -49,20 +49,20 @@ o.spec("updateFragment", function() {
|
|||
o("updates from childless fragment", function() {
|
||||
var vnode = {tag: "["}
|
||||
var updated = {tag: "[", children: [{tag: "a"}]}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeName).equals("A")
|
||||
})
|
||||
o("updates to childless fragment", function() {
|
||||
var vnode = {tag: "[", children: [{tag: "a"}]}
|
||||
var updated = {tag: "["}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(null)
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,20 +15,20 @@ o.spec("updateHTML", function() {
|
|||
o("updates html", function() {
|
||||
var vnode = {tag: "<", children: "a"}
|
||||
var updated = {tag: "<", children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("b")
|
||||
})
|
||||
o("adds html", function() {
|
||||
var vnode = {tag: "<", children: ""}
|
||||
var updated = {tag: "<", children: "<a></a><b></b>"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.domSize).equals(2)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(root.childNodes.length).equals(2)
|
||||
|
|
@ -38,10 +38,10 @@ o.spec("updateHTML", function() {
|
|||
o("removes html", function() {
|
||||
var vnode = {tag: "<", children: "<a></a><b></b>"}
|
||||
var updated = {tag: "<", children: ""}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(null)
|
||||
o(updated.domSize).equals(0)
|
||||
o(root.childNodes.length).equals(0)
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles el noop", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -28,10 +28,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles el noop without key", function() {
|
||||
var vnodes = [{tag: "a"}, {tag: "b"}]
|
||||
var updated = [{tag: "a"}, {tag: "b"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -41,10 +41,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles text noop", function() {
|
||||
var vnodes = [{tag: "#", children: "a"}]
|
||||
var updated = [{tag: "#", children: "a"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeValue).equals("a")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -52,10 +52,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles text noop w/ type casting", function() {
|
||||
var vnodes = [{tag: "#", children: 1}]
|
||||
var updated = [{tag: "#", children: "1"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeValue).equals("1")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -63,10 +63,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles falsy text noop w/ type casting", function() {
|
||||
var vnodes = [{tag: "#", children: 0}]
|
||||
var updated = [{tag: "#", children: "0"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeValue).equals("0")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -74,10 +74,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles html noop", function() {
|
||||
var vnodes = [{tag: "<", children: "a"}]
|
||||
var updated = [{tag: "<", children: "a"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeValue).equals("a")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -85,10 +85,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles fragment noop", function() {
|
||||
var vnodes = [{tag: "[", children: [{tag: "a"}]}]
|
||||
var updated = [{tag: "[", children: [{tag: "a"}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -96,10 +96,10 @@ o.spec("updateNodes", function() {
|
|||
o("handles fragment noop w/ text child", function() {
|
||||
var vnodes = [{tag: "[", children: [{tag: "#", children: "a"}]}]
|
||||
var updated = [{tag: "[", children: [{tag: "#", children: "a"}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeValue).equals("a")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -107,10 +107,10 @@ o.spec("updateNodes", function() {
|
|||
o("reverses els w/ even count", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(updated[0].dom.nodeName).equals("S")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -124,10 +124,10 @@ o.spec("updateNodes", function() {
|
|||
o("reverses els w/ odd count", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||
var updated = [{tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -139,10 +139,10 @@ o.spec("updateNodes", function() {
|
|||
o("creates el at start", function() {
|
||||
var vnodes = [{tag: "a", key: 1}]
|
||||
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("B")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -152,10 +152,10 @@ o.spec("updateNodes", function() {
|
|||
o("creates el at end", function() {
|
||||
var vnodes = [{tag: "a", key: 1}]
|
||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -165,10 +165,10 @@ o.spec("updateNodes", function() {
|
|||
o("creates el in middle", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
o(updated[1].dom.nodeName).equals("I")
|
||||
|
|
@ -179,10 +179,10 @@ o.spec("updateNodes", function() {
|
|||
o("creates el while reversing", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("B")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -194,10 +194,10 @@ o.spec("updateNodes", function() {
|
|||
o("deletes el at start", function() {
|
||||
var vnodes = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||
var updated = [{tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -205,10 +205,10 @@ o.spec("updateNodes", function() {
|
|||
o("deletes el at end", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -216,10 +216,10 @@ o.spec("updateNodes", function() {
|
|||
o("deletes el at middle", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -229,10 +229,10 @@ o.spec("updateNodes", function() {
|
|||
o("deletes el while reversing", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("B")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -242,10 +242,10 @@ o.spec("updateNodes", function() {
|
|||
o("creates, deletes, reverses els at same time", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}, {tag: "s", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("B")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -257,10 +257,10 @@ o.spec("updateNodes", function() {
|
|||
o("adds to empty array followed by el", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}]}, {tag: "b", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].children[0].dom.nodeName).equals("A")
|
||||
o(updated[0].children[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -270,10 +270,10 @@ o.spec("updateNodes", function() {
|
|||
o("reverses followed by el", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: [{tag: "a", key: 2}, {tag: "b", key: 3}]}, {tag: "i", key: 4}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "b", key: 3}, {tag: "a", key: 2}]}, {tag: "i", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].children[0].dom.nodeName).equals("B")
|
||||
o(updated[0].children[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -285,10 +285,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates empty array to html with same key", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: []}]
|
||||
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -299,10 +299,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates empty html to array with same key", function() {
|
||||
var vnodes = [{tag: "<", key: 1, children: ""}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -313,10 +313,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates empty array to html without key", function() {
|
||||
var vnodes = [{tag: "[", children: []}]
|
||||
var updated = [{tag: "<", children: "<a></a><b></b>"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -327,10 +327,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates empty html to array without key", function() {
|
||||
var vnodes = [{tag: "<", children: ""}]
|
||||
var updated = [{tag: "[", children: [{tag: "a"}, {tag: "b"}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -341,10 +341,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates array to html with same key", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}]
|
||||
var updated = [{tag: "<", key: 1, children: "<i></i><s></s>"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -355,10 +355,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates html to array with same key", function() {
|
||||
var vnodes = [{tag: "<", key: 1, children: "<a></a><b></b>"}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "i"}, {tag: "s"}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -369,10 +369,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates array to html without key", function() {
|
||||
var vnodes = [{tag: "[", children: [{tag: "a"}, {tag: "b"}]}]
|
||||
var updated = [{tag: "<", children: "<i></i><s></s>"}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -383,10 +383,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates html to array without key", function() {
|
||||
var vnodes = [{tag: "<", children: "<a></a><b></b>"}]
|
||||
var updated = [{tag: "[", children: [{tag: "i"}, {tag: "s"}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -397,10 +397,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates empty array to html with same key followed by el", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "i", key: 2}]
|
||||
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}, {tag: "i", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -413,10 +413,10 @@ o.spec("updateNodes", function() {
|
|||
o("updates empty html to array with same key followed by el", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "i", key: 2}]
|
||||
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}, {tag: "i", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -429,10 +429,10 @@ o.spec("updateNodes", function() {
|
|||
o("populates array followed by null then el", function() {
|
||||
var vnodes = [{tag: "[", key: 1, children: []}, null, {tag: "i", key: 2}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, null, {tag: "i", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -445,10 +445,10 @@ o.spec("updateNodes", function() {
|
|||
o("populates childless array followed by el", function() {
|
||||
var vnodes = [{tag: "[", key: 1}, {tag: "i", key: 2}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, {tag: "i", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -461,10 +461,10 @@ o.spec("updateNodes", function() {
|
|||
o("populates childless array followed by null then el", function() {
|
||||
var vnodes = [{tag: "[", key: 1}, null, {tag: "i", key: 2}]
|
||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, null, {tag: "i", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -477,10 +477,10 @@ o.spec("updateNodes", function() {
|
|||
o("moves from end to start", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(updated[0].dom.nodeName).equals("S")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -494,10 +494,10 @@ o.spec("updateNodes", function() {
|
|||
o("moves from start to end", function() {
|
||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
var updated = [{tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(updated[0].dom.nodeName).equals("B")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -512,11 +512,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -531,11 +531,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
var temp = []
|
||||
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(4)
|
||||
o(updated[0].dom.nodeName).equals("S")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -550,11 +550,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -563,11 +563,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -580,11 +580,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -595,11 +595,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "i", key: 3}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -608,11 +608,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "i", key: 3}, {tag: "s", key: 4}, {tag: "div", key: 5}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("I")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -625,11 +625,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1}, {tag: "s", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -640,11 +640,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("S")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -655,11 +655,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1}, {tag: "s", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -670,11 +670,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||
var temp = []
|
||||
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("S")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -685,11 +685,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -702,11 +702,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "a", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(3)
|
||||
o(updated[0].dom.nodeName).equals("S")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -720,12 +720,12 @@ o.spec("updateNodes", function() {
|
|||
var temp1 = []
|
||||
var temp2 = [{tag: "a", key: 1, children: [{tag: "i", key: 3}, {tag: "s", key: 4}]}, {tag: "b", key: 2}]
|
||||
var updated = [{tag: "a", key: 1, children: [{tag: "s", key: 4}, {tag: "i", key: 3}]}, {tag: "b", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp1)
|
||||
render(root, temp2)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(updated[0].dom.nodeName).equals("A")
|
||||
o(updated[0].dom).equals(root.childNodes[0])
|
||||
|
|
@ -739,11 +739,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "a", key: 1, children: [{tag: "a", key: 3, children: [{tag: "a", key: 5}]}, {tag: "a", key: 4, children: [{tag: "a", key: 5}]}]}, {tag: "a", key: 2}]
|
||||
var temp = []
|
||||
var updated = [{tag: "a", key: 1, children: [{tag: "a", key: 3, children: [{tag: "a", key: 5}]}, {tag: "a", key: 4, children: [{tag: "a", key: 5}]}]}, {tag: "a", key: 2}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(root.childNodes.length).equals(2)
|
||||
o(root.childNodes[0].childNodes.length).equals(2)
|
||||
o(root.childNodes[0].childNodes[0].childNodes.length).equals(1)
|
||||
|
|
@ -754,11 +754,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "div", key: 1}]
|
||||
var temp = []
|
||||
var updated = [{tag: "div", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(vnodes[0].dom).equals(updated[0].dom)
|
||||
o(updated[0].dom.nodeName).equals("DIV")
|
||||
})
|
||||
|
|
@ -766,11 +766,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "div", key: 1}]
|
||||
var temp = [{tag: "div"}]
|
||||
var updated = [{tag: "div", key: 1}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(vnodes[0].dom).equals(updated[0].dom)
|
||||
o(updated[0].dom.nodeName).equals("DIV")
|
||||
})
|
||||
|
|
@ -778,11 +778,11 @@ o.spec("updateNodes", function() {
|
|||
var vnodes = [{tag: "div", children: [{tag: "a", key: 1}]}]
|
||||
var temp = [{tag: "div"}]
|
||||
var updated = [{tag: "div", children: [{tag: "a", key: 1}]}]
|
||||
|
||||
|
||||
render(root, vnodes)
|
||||
render(root, temp)
|
||||
render(root, updated)
|
||||
|
||||
|
||||
o(vnodes[0].dom.firstChild).equals(updated[0].dom.firstChild)
|
||||
o(updated[0].dom.firstChild.nodeName).equals("A")
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ o.spec("updateText", function() {
|
|||
o("updates to string", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
var updated = {tag: "#", children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("b")
|
||||
|
|
@ -26,10 +26,10 @@ o.spec("updateText", function() {
|
|||
o("updates to falsy string", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
var updated = {tag: "#", children: ""}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("")
|
||||
|
|
@ -37,10 +37,10 @@ o.spec("updateText", function() {
|
|||
o("updates from falsy string", function() {
|
||||
var vnode = {tag: "#", children: ""}
|
||||
var updated = {tag: "#", children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("b")
|
||||
|
|
@ -48,10 +48,10 @@ o.spec("updateText", function() {
|
|||
o("updates to number", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
var updated = {tag: "#", children: 1}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("1")
|
||||
|
|
@ -59,10 +59,10 @@ o.spec("updateText", function() {
|
|||
o("updates to falsy number", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
var updated = {tag: "#", children: 0}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("0")
|
||||
|
|
@ -70,10 +70,10 @@ o.spec("updateText", function() {
|
|||
o("updates from falsy number", function() {
|
||||
var vnode = {tag: "#", children: 0}
|
||||
var updated = {tag: "#", children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("b")
|
||||
|
|
@ -81,10 +81,10 @@ o.spec("updateText", function() {
|
|||
o("updates to boolean", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
var updated = {tag: "#", children: true}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("true")
|
||||
|
|
@ -92,10 +92,10 @@ o.spec("updateText", function() {
|
|||
o("updates to falsy boolean", function() {
|
||||
var vnode = {tag: "#", children: "a"}
|
||||
var updated = {tag: "#", children: false}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("false")
|
||||
|
|
@ -103,10 +103,10 @@ o.spec("updateText", function() {
|
|||
o("updates from falsy boolean", function() {
|
||||
var vnode = {tag: "#", children: false}
|
||||
var updated = {tag: "#", children: "b"}
|
||||
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
|
||||
o(updated.dom).equals(vnode.dom)
|
||||
o(updated.dom).equals(root.firstChild)
|
||||
o(updated.dom.nodeValue).equals("b")
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@ var Node = require("../render/node")
|
|||
|
||||
module.exports = function(html) {
|
||||
return Node("<", undefined, undefined, html, undefined, undefined)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,27 +8,27 @@ module.exports = function($window, Promise) {
|
|||
function xhr(args) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
||||
|
||||
|
||||
if (typeof args.serialize !== "function") args.serialize = JSON.stringify
|
||||
if (typeof args.deserialize !== "function") args.deserialize = deserialize
|
||||
if (typeof args.extract !== "function") args.extract = extract
|
||||
|
||||
|
||||
args.url = interpolate(args.url, args.data)
|
||||
if (useBody) args.data = args.serialize(args.data)
|
||||
else args.url = assemble(args.url, args.data)
|
||||
|
||||
|
||||
var xhr = new $window.XMLHttpRequest()
|
||||
xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
|
||||
|
||||
|
||||
if (args.serialize === JSON.stringify && useBody) {
|
||||
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
|
||||
}
|
||||
if (args.deserialize === deserialize) {
|
||||
xhr.setRequestHeader("Accept", "application/json, text/*")
|
||||
}
|
||||
|
||||
|
||||
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
|
||||
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
try {
|
||||
|
|
@ -42,7 +42,7 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
else response = new args.type(response)
|
||||
}
|
||||
|
||||
|
||||
resolve(response)
|
||||
}
|
||||
else reject(new Error(xhr.responseText))
|
||||
|
|
@ -52,7 +52,7 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (useBody) xhr.send(args.data)
|
||||
else xhr.send()
|
||||
})
|
||||
|
|
@ -82,7 +82,7 @@ module.exports = function($window, Promise) {
|
|||
|
||||
function interpolate(url, data) {
|
||||
if (data == null) return url
|
||||
|
||||
|
||||
var tokens = url.match(/:[^\/]+/gi) || []
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var key = tokens[i].slice(1)
|
||||
|
|
@ -109,6 +109,6 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
|
||||
function extract(xhr) {return xhr.responseText}
|
||||
|
||||
|
||||
return {xhr: xhr, jsonp: jsonp}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<script src="../../request/request.js"></script>
|
||||
<script src="test-xhr.js"></script>
|
||||
<script src="test-jsonp.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ o.spec("jsonp", function() {
|
|||
mock = xhrMock()
|
||||
jsonp = new Request(mock, Promise).jsonp
|
||||
})
|
||||
|
||||
|
||||
o("works", function(done) {
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
|
|
@ -52,4 +52,4 @@ o.spec("jsonp", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ o.spec("xhr", function() {
|
|||
mock = xhrMock()
|
||||
xhr = new Request(mock, Promise).xhr
|
||||
})
|
||||
|
||||
|
||||
o.spec("success", function() {
|
||||
o("works via GET", function(done) {
|
||||
var s = new Date
|
||||
|
|
@ -119,7 +119,7 @@ o.spec("xhr", function() {
|
|||
var Entity = function(args) {
|
||||
return {_id: args.id}
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])}
|
||||
|
|
@ -133,7 +133,7 @@ o.spec("xhr", function() {
|
|||
var Entity = function(args) {
|
||||
return {_id: args.id}
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({id: 1})}
|
||||
|
|
@ -147,7 +147,7 @@ o.spec("xhr", function() {
|
|||
var serialize = function(data) {
|
||||
return "id=" + data.id
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({body: request.query})}
|
||||
|
|
@ -161,7 +161,7 @@ o.spec("xhr", function() {
|
|||
var serialize = function(data) {
|
||||
return "id=" + data.id
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({body: request.body})}
|
||||
|
|
@ -175,7 +175,7 @@ o.spec("xhr", function() {
|
|||
var deserialize = function(data) {
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||
|
|
@ -189,7 +189,7 @@ o.spec("xhr", function() {
|
|||
var deserialize = function(data) {
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||
|
|
@ -203,7 +203,7 @@ o.spec("xhr", function() {
|
|||
var extract = function(data) {
|
||||
return JSON.stringify({test: 123})
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
|
|
@ -217,7 +217,7 @@ o.spec("xhr", function() {
|
|||
var extract = function(data) {
|
||||
return JSON.stringify({test: 123})
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
|
|
@ -234,7 +234,7 @@ o.spec("xhr", function() {
|
|||
}
|
||||
})
|
||||
xhr({method: "POST", url: "/item", config: config}).then(done)
|
||||
|
||||
|
||||
function config(xhr) {
|
||||
o(typeof xhr.setRequestHeader).equals("function")
|
||||
o(typeof xhr.open).equals("function")
|
||||
|
|
@ -264,4 +264,4 @@ o.spec("xhr", function() {
|
|||
}).then(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@ var parseQueryString = require("../querystring/parse")
|
|||
|
||||
module.exports = function($window) {
|
||||
var supportsPushState = typeof $window.history.pushState === "function" && $window.location.protocol !== "file:"
|
||||
|
||||
|
||||
var prefix = "#!"
|
||||
function setPrefix(value) {prefix = value}
|
||||
|
||||
|
||||
function normalize(fragment) {
|
||||
var data = $window.location[fragment].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)
|
||||
if (fragment === "pathname" && data[0] !== "/") data = "/" + data
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
function parsePath(path, queryData, hashData) {
|
||||
var queryIndex = path.indexOf("?")
|
||||
var hashIndex = path.indexOf("#")
|
||||
|
|
@ -50,13 +50,13 @@ module.exports = function($window) {
|
|||
return data[token]
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
var query = buildQueryString(queryData)
|
||||
if (query) path += "?" + query
|
||||
|
||||
|
||||
var hash = buildQueryString(hashData)
|
||||
if (hash) path += "#" + hash
|
||||
|
||||
|
||||
if (supportsPushState) {
|
||||
if (options && options.replace) $window.history.replaceState(null, null, prefix + path)
|
||||
else $window.history.pushState(null, null, prefix + path)
|
||||
|
|
@ -64,20 +64,20 @@ module.exports = function($window) {
|
|||
}
|
||||
else $window.location.href = prefix + path
|
||||
}
|
||||
|
||||
|
||||
function defineRoutes(routes, resolve, reject) {
|
||||
if (supportsPushState) $window.onpopstate = resolveRoute
|
||||
else if (prefix.charAt(0) === "#") $window.onhashchange = resolveRoute
|
||||
resolveRoute()
|
||||
|
||||
|
||||
function resolveRoute() {
|
||||
var path = getPath()
|
||||
var params = {}
|
||||
var pathname = parsePath(path, params, params)
|
||||
|
||||
|
||||
for (var route in routes) {
|
||||
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
|
||||
|
||||
|
||||
if (matcher.test(pathname)) {
|
||||
pathname.replace(matcher, function() {
|
||||
var keys = route.match(/:[^\/]+/g) || []
|
||||
|
|
@ -90,12 +90,12 @@ module.exports = function($window) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reject(path, params)
|
||||
}
|
||||
return resolveRoute
|
||||
}
|
||||
|
||||
|
||||
function link(vnode) {
|
||||
vnode.dom.setAttribute("href", prefix + vnode.attrs.href)
|
||||
vnode.dom.onclick = function(e) {
|
||||
|
|
@ -103,6 +103,6 @@ module.exports = function($window) {
|
|||
setPath(vnode.attrs.href, undefined, undefined)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {setPrefix: setPrefix, getPath: getPath, setPath: setPath, defineRoutes: defineRoutes, link: link}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<script src="test-defineRoutes.js"></script>
|
||||
<script src="test-getPath.js"></script>
|
||||
<script src="test-setPath.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
||||
o.spec("using prefix `" + prefix + "`", function() {
|
||||
var $window, router, onRouteChange, onFail
|
||||
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = pushStateMock()
|
||||
router = new Router($window)
|
||||
|
|
@ -16,195 +16,195 @@ o.spec("Router.defineRoutes", function() {
|
|||
onRouteChange = o.spy()
|
||||
onFail = o.spy()
|
||||
})
|
||||
|
||||
|
||||
o("resolves to route", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("resolves to route w/ escaped unicode", function() {
|
||||
$window.location.href = prefix + "/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6"
|
||||
router.defineRoutes({"/ö": {data: 2}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("resolves to route w/ unicode", function() {
|
||||
$window.location.href = prefix + "/ö?ö=ö#ö=ö"
|
||||
router.defineRoutes({"/ö": {data: 2}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("resolves to route on fallback mode", function() {
|
||||
$window.location.href = "file://" + prefix + "/test"
|
||||
|
||||
|
||||
router = new Router($window)
|
||||
router.setPrefix(prefix)
|
||||
|
||||
|
||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("handles parameterized route", function() {
|
||||
$window.location.href = prefix + "/test/x"
|
||||
router.defineRoutes({"/test/:a": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x"}, "/test/x", "/test/:a"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("handles multi-parameterized route", function() {
|
||||
$window.location.href = prefix + "/test/x/y"
|
||||
router.defineRoutes({"/test/:a/:b": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x", b: "y"}, "/test/x/y", "/test/:a/:b"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("handles rest parameterized route", function() {
|
||||
$window.location.href = prefix + "/test/x/y"
|
||||
router.defineRoutes({"/test/:a...": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x/y"}, "/test/x/y", "/test/:a..."])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("handles route with search", function() {
|
||||
$window.location.href = prefix + "/test?a=b&c=d"
|
||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b&c=d", "/test"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("handles route with hash", function() {
|
||||
$window.location.href = prefix + "/test#a=b&c=d"
|
||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test#a=b&c=d", "/test"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("handles route with search and hash", function() {
|
||||
$window.location.href = prefix + "/test?a=b#c=d"
|
||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b#c=d", "/test"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
|
||||
|
||||
o("calls reject", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/other": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onFail.callCount).equals(1)
|
||||
o(onFail.args).deepEquals(["/test", {}])
|
||||
})
|
||||
|
||||
|
||||
o("calls reject w/ search and hash", function() {
|
||||
$window.location.href = prefix + "/test?a=b#c=d"
|
||||
router.defineRoutes({"/other": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onFail.callCount).equals(1)
|
||||
o(onFail.args).deepEquals(["/test?a=b#c=d", {a: "b", c: "d"}])
|
||||
})
|
||||
|
||||
|
||||
o("handles out of order routes", function() {
|
||||
$window.location.href = prefix + "/z/y/x"
|
||||
router.defineRoutes({"/z/y/x": {data: 1}, "/:a...": {data: 2}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||
})
|
||||
|
||||
|
||||
o("handles reverse out of order routes", function() {
|
||||
$window.location.href = prefix + "/z/y/x"
|
||||
router.defineRoutes({"/:a...": {data: 2}, "/z/y/x": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||
})
|
||||
|
||||
|
||||
o("handles dynamically added out of order routes", function() {
|
||||
var routes = {}
|
||||
routes["/z/y/x"] = {data: 1}
|
||||
routes["/:a..."] = {data: 2}
|
||||
|
||||
|
||||
$window.location.href = prefix + "/z/y/x"
|
||||
router.defineRoutes(routes, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||
})
|
||||
|
||||
|
||||
o("handles reversed dynamically added out of order routes", function() {
|
||||
var routes = {}
|
||||
routes["/:a..."] = {data: 2}
|
||||
routes["/z/y/x"] = {data: 1}
|
||||
|
||||
|
||||
$window.location.href = prefix + "/z/y/x"
|
||||
router.defineRoutes(routes, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||
})
|
||||
|
||||
|
||||
o("handles mixed out of order routes", function() {
|
||||
var routes = {"/z/y/x": {data: 1}}
|
||||
routes["/:a..."] = {data: 2}
|
||||
|
||||
|
||||
$window.location.href = prefix + "/z/y/x"
|
||||
router.defineRoutes(routes, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||
})
|
||||
|
||||
|
||||
o("handles reverse mixed out of order routes", function() {
|
||||
var routes = {"/:a...": {data: 2}}
|
||||
routes["/z/y/x"] = {data: 12}
|
||||
|
||||
|
||||
$window.location.href = prefix + "/z/y/x"
|
||||
router.defineRoutes(routes, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||
})
|
||||
|
||||
|
||||
o("handles non-ascii routes", function() {
|
||||
$window.location.href = prefix + "/ö"
|
||||
router.defineRoutes({"/ö": "aaa"}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
})
|
||||
|
||||
|
||||
o("replays", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
var replay = router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
replay()
|
||||
|
||||
|
||||
o(onRouteChange.callCount).equals(2)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ o.spec("Router.getPath", function() {
|
|||
void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) {
|
||||
o.spec("using prefix `" + prefix + "`", function() {
|
||||
var $window, router, onRouteChange, onFail
|
||||
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = pushStateMock()
|
||||
router = new Router($window)
|
||||
|
|
@ -16,31 +16,31 @@ o.spec("Router.getPath", function() {
|
|||
onRouteChange = o.spy()
|
||||
onFail = o.spy()
|
||||
})
|
||||
|
||||
|
||||
o("gets route", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(router.getPath()).equals("/test")
|
||||
})
|
||||
o("gets route w/ params", function() {
|
||||
$window.location.href = prefix + "/other/x/y/z?c=d#e=f"
|
||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||
})
|
||||
o("gets route w/ escaped unicode", function() {
|
||||
$window.location.href = prefix + "/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6"
|
||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||
})
|
||||
o("gets route w/ unicode", function() {
|
||||
$window.location.href = prefix + "/ö?ö=ö#ö=ö"
|
||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
|
||||
|
||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ o.spec("Router.setPath", function() {
|
|||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
||||
o.spec("using prefix `" + prefix + "`", function() {
|
||||
var $window, router, onRouteChange, onFail
|
||||
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = pushStateMock()
|
||||
router = new Router($window)
|
||||
|
|
@ -16,38 +16,38 @@ o.spec("Router.setPath", function() {
|
|||
onRouteChange = o.spy()
|
||||
onFail = o.spy()
|
||||
})
|
||||
|
||||
|
||||
o("sets route via API", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
router.setPath("/other/x/y/z?c=d#e=f")
|
||||
|
||||
|
||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||
})
|
||||
o("sets route w/ escaped unicode", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
router.setPath("/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6")
|
||||
|
||||
|
||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||
})
|
||||
o("sets route w/ unicode", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
router.setPath("/ö?ö=ö#ö=ö")
|
||||
|
||||
|
||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||
})
|
||||
|
||||
|
||||
o("sets route on fallback mode", function() {
|
||||
$window.location.href = "file://" + prefix + "/test"
|
||||
|
||||
|
||||
router = new Router($window)
|
||||
router.setPrefix(prefix)
|
||||
|
||||
|
||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
router.setPath("/other/x/y/z?c=d#e=f")
|
||||
|
||||
|
||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||
})
|
||||
o("sets route via pushState/onpopstate", function() {
|
||||
|
|
@ -55,14 +55,14 @@ o.spec("Router.setPath", function() {
|
|||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
$window.history.pushState(null, null, prefix + "/other/x/y/z?c=d#e=f")
|
||||
$window.onpopstate()
|
||||
|
||||
|
||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||
})
|
||||
o("sets parameterized route", function() {
|
||||
$window.location.href = prefix + "/test"
|
||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||
router.setPath("/other/:a/:b", {a: "x", b: "y/z", c: "d", e: "f"})
|
||||
|
||||
|
||||
o(router.getPath()).equals("/other/x/y/z?c=d&e=f")
|
||||
})
|
||||
o("replace:true works", function() {
|
||||
|
|
@ -70,7 +70,7 @@ o.spec("Router.setPath", function() {
|
|||
router.defineRoutes({"/test": {data: 1}, "/other": {data: 2}}, onRouteChange, onFail)
|
||||
router.setPath("/other", null, {replace: true})
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.location.href).equals("http://localhost/")
|
||||
})
|
||||
o("replace:false works", function() {
|
||||
|
|
@ -85,4 +85,4 @@ o.spec("Router.setPath", function() {
|
|||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@ License: MIT
|
|||
|
||||
- pushStateMock - mock for `history.pushState` and `location`
|
||||
- ajaxMock - mock for XMLHttpRequest and JSONP transporters
|
||||
- parseURL - helper function for URL parsing
|
||||
- parseURL - helper function for URL parsing
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
"use strict"
|
||||
|
||||
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout
|
||||
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ module.exports = function() {
|
|||
var ancestor = this
|
||||
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
|
||||
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
|
||||
|
||||
|
||||
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
|
||||
|
||||
|
||||
var index = this.childNodes.indexOf(child)
|
||||
if (index > -1) this.childNodes.splice(index, 1)
|
||||
if (child.nodeType === 11) {
|
||||
|
|
@ -35,9 +35,9 @@ module.exports = function() {
|
|||
var ancestor = this
|
||||
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
|
||||
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
|
||||
|
||||
|
||||
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
|
||||
|
||||
|
||||
var refIndex = this.childNodes.indexOf(reference)
|
||||
var index = this.childNodes.indexOf(child)
|
||||
if (reference !== null && refIndex < 0) throw new TypeError("Invalid argument")
|
||||
|
|
@ -109,7 +109,7 @@ module.exports = function() {
|
|||
},
|
||||
set innerHTML(value) {
|
||||
while (this.firstChild) this.removeChild(this.firstChild)
|
||||
|
||||
|
||||
var stack = [this], depth = 0, voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]
|
||||
value.replace(/<([a-z0-9\-]+?)((?:\s+?[^=]+?=(?:"[^"]*?"|'[^']*?'|[^\s>]*))*?)(\s*\/)?>|<\/([a-z0-9\-]+?)>|([^<]+)/g, function(match, startTag, attrs, selfClosed, endTag, text) {
|
||||
if (startTag) {
|
||||
|
|
@ -173,7 +173,7 @@ module.exports = function() {
|
|||
if (this.nodeName === "INPUT" && this.attributes["type"] != null && this.attributes["type"].nodeValue === "checkbox" && e.type === "click") {
|
||||
this.checked = !this.checked
|
||||
}
|
||||
|
||||
|
||||
e.target = this
|
||||
if (events[e.type] != null) {
|
||||
for (var i = 0; i < events[e.type].length; i++) {
|
||||
|
|
@ -186,7 +186,7 @@ module.exports = function() {
|
|||
if (typeof this["on" + e.type] === "function" && !isModernEvent(e.type)) this["on" + e.type](e)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
if (element.nodeName === "A") {
|
||||
var href
|
||||
Object.defineProperty(element, "href", {
|
||||
|
|
@ -195,7 +195,7 @@ module.exports = function() {
|
|||
enumerable: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (element.nodeName === "INPUT") {
|
||||
var checked
|
||||
Object.defineProperty(element, "checked", {
|
||||
|
|
@ -203,10 +203,10 @@ module.exports = function() {
|
|||
set: function(value) {checked = Boolean(value)},
|
||||
enumerable: true,
|
||||
})
|
||||
|
||||
|
||||
element.value = ""
|
||||
}
|
||||
|
||||
|
||||
if (element.nodeName === "TEXTAREA") {
|
||||
var value
|
||||
Object.defineProperty(element, "value", {
|
||||
|
|
@ -218,7 +218,7 @@ module.exports = function() {
|
|||
enumerable: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function getOptions(element) {
|
||||
var options = []
|
||||
for (var i = 0; i < element.childNodes.length; i++) {
|
||||
|
|
@ -340,6 +340,6 @@ module.exports = function() {
|
|||
$window.document.body = $window.document.createElement("body")
|
||||
$window.document.documentElement.appendChild($window.document.body)
|
||||
activeElement = $window.document.body
|
||||
|
||||
|
||||
return $window
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ module.exports = function() {
|
|||
var pathname = "/"
|
||||
var search = ""
|
||||
var hash = ""
|
||||
|
||||
|
||||
var past = [], future = []
|
||||
|
||||
|
||||
function getURL() {
|
||||
if (protocol === "file:") return protocol + "//" + pathname + search + hash
|
||||
return protocol + "//" + hostname + prefix(":", port) + pathname + search + hash
|
||||
|
|
@ -75,7 +75,7 @@ module.exports = function() {
|
|||
get href() {
|
||||
return getURL()
|
||||
},
|
||||
|
||||
|
||||
set protocol(value) {
|
||||
throw new Error("Protocol is read-only")
|
||||
},
|
||||
|
|
@ -112,7 +112,7 @@ module.exports = function() {
|
|||
hash = prefix("#", value)
|
||||
if (oldHash != hash) hashchange()
|
||||
},
|
||||
|
||||
|
||||
set origin(value) {
|
||||
//origin is writable but ignored
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<script src="test-pushStateMock.js"></script>
|
||||
<script src="test-xhrMock.js"></script>
|
||||
<script src="test-domMock.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ o.spec("domMock", function() {
|
|||
o.beforeEach(function() {
|
||||
$document = domMock().document
|
||||
})
|
||||
|
||||
|
||||
o.spec("createElement", function() {
|
||||
o("works", function() {
|
||||
var node = $document.createElement("div")
|
||||
|
||||
|
||||
o(node.nodeType).equals(1)
|
||||
o(node.nodeName).equals("DIV")
|
||||
o(node.namespaceURI).equals("http://www.w3.org/1999/xhtml")
|
||||
|
|
@ -22,11 +22,11 @@ o.spec("domMock", function() {
|
|||
o(node.nextSibling).equals(null)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("createElementNS", function() {
|
||||
o("works", function() {
|
||||
var node = $document.createElementNS("http://www.w3.org/2000/svg", "svg")
|
||||
|
||||
|
||||
o(node.nodeType).equals(1)
|
||||
o(node.nodeName).equals("svg")
|
||||
o(node.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||
|
|
@ -36,11 +36,11 @@ o.spec("domMock", function() {
|
|||
o(node.nextSibling).equals(null)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("createTextNode", function() {
|
||||
o("works", function() {
|
||||
var node = $document.createTextNode("abc")
|
||||
|
||||
|
||||
o(node.nodeType).equals(3)
|
||||
o(node.nodeName).equals("#text")
|
||||
o(node.parentNode).equals(null)
|
||||
|
|
@ -48,41 +48,41 @@ o.spec("domMock", function() {
|
|||
})
|
||||
o("works w/ number", function() {
|
||||
var node = $document.createTextNode(123)
|
||||
|
||||
|
||||
o(node.nodeValue).equals("123")
|
||||
})
|
||||
o("works w/ null", function() {
|
||||
var node = $document.createTextNode(null)
|
||||
|
||||
|
||||
o(node.nodeValue).equals("null")
|
||||
})
|
||||
o("works w/ undefined", function() {
|
||||
var node = $document.createTextNode(undefined)
|
||||
|
||||
|
||||
o(node.nodeValue).equals("undefined")
|
||||
})
|
||||
o("works w/ object", function() {
|
||||
var node = $document.createTextNode({})
|
||||
|
||||
|
||||
o(node.nodeValue).equals("[object Object]")
|
||||
})
|
||||
o("does not unescape HTML", function() {
|
||||
var node = $document.createTextNode("<a>&</a>")
|
||||
|
||||
|
||||
o(node.nodeValue).equals("<a>&</a>")
|
||||
})
|
||||
o("nodeValue casts to string", function() {
|
||||
var node = $document.createTextNode("a")
|
||||
node.nodeValue = true
|
||||
|
||||
|
||||
o(node.nodeValue).equals("true")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("createDocumentFragment", function() {
|
||||
o("works", function() {
|
||||
var node = $document.createDocumentFragment()
|
||||
|
||||
|
||||
o(node.nodeType).equals(11)
|
||||
o(node.nodeName).equals("#document-fragment")
|
||||
o(node.parentNode).equals(null)
|
||||
|
|
@ -90,13 +90,13 @@ o.spec("domMock", function() {
|
|||
o(node.firstChild).equals(null)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("appendChild", function() {
|
||||
o("works", function() {
|
||||
var parent = $document.createElement("div")
|
||||
var child = $document.createElement("a")
|
||||
parent.appendChild(child)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(1)
|
||||
o(parent.childNodes[0]).equals(child)
|
||||
o(parent.firstChild).equals(child)
|
||||
|
|
@ -109,7 +109,7 @@ o.spec("domMock", function() {
|
|||
parent.appendChild(a)
|
||||
parent.appendChild(b)
|
||||
parent.appendChild(a)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(2)
|
||||
o(parent.childNodes[0]).equals(b)
|
||||
o(parent.childNodes[1]).equals(a)
|
||||
|
|
@ -126,7 +126,7 @@ o.spec("domMock", function() {
|
|||
parent.appendChild(a)
|
||||
source.appendChild(b)
|
||||
parent.appendChild(b)
|
||||
|
||||
|
||||
o(source.childNodes.length).equals(0)
|
||||
})
|
||||
o("transfers from fragment", function() {
|
||||
|
|
@ -137,7 +137,7 @@ o.spec("domMock", function() {
|
|||
a.appendChild(b)
|
||||
a.appendChild(c)
|
||||
parent.appendChild(a)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(2)
|
||||
o(parent.childNodes[0]).equals(b)
|
||||
o(parent.childNodes[1]).equals(c)
|
||||
|
|
@ -168,14 +168,14 @@ o.spec("domMock", function() {
|
|||
catch (e) {done()}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("removeChild", function() {
|
||||
o("works", function() {
|
||||
var parent = $document.createElement("div")
|
||||
var child = $document.createElement("a")
|
||||
parent.appendChild(child)
|
||||
parent.removeChild(child)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(0)
|
||||
o(parent.firstChild).equals(null)
|
||||
o(child.parentNode).equals(null)
|
||||
|
|
@ -187,7 +187,7 @@ o.spec("domMock", function() {
|
|||
catch (e) {done()}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("insertBefore", function() {
|
||||
o("works", function() {
|
||||
var parent = $document.createElement("div")
|
||||
|
|
@ -195,7 +195,7 @@ o.spec("domMock", function() {
|
|||
var b = $document.createElement("b")
|
||||
parent.appendChild(a)
|
||||
parent.insertBefore(b, a)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(2)
|
||||
o(parent.childNodes[0]).equals(b)
|
||||
o(parent.childNodes[1]).equals(a)
|
||||
|
|
@ -211,7 +211,7 @@ o.spec("domMock", function() {
|
|||
parent.appendChild(a)
|
||||
parent.appendChild(b)
|
||||
parent.insertBefore(b, a)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(2)
|
||||
o(parent.childNodes[0]).equals(b)
|
||||
o(parent.childNodes[1]).equals(a)
|
||||
|
|
@ -228,7 +228,7 @@ o.spec("domMock", function() {
|
|||
parent.appendChild(a)
|
||||
source.appendChild(b)
|
||||
parent.insertBefore(b, a)
|
||||
|
||||
|
||||
o(source.childNodes.length).equals(0)
|
||||
})
|
||||
o("transfers from fragment", function() {
|
||||
|
|
@ -241,7 +241,7 @@ o.spec("domMock", function() {
|
|||
a.appendChild(b)
|
||||
a.appendChild(c)
|
||||
parent.insertBefore(a, ref)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(3)
|
||||
o(parent.childNodes[0]).equals(b)
|
||||
o(parent.childNodes[1]).equals(c)
|
||||
|
|
@ -261,7 +261,7 @@ o.spec("domMock", function() {
|
|||
var b = $document.createElement("b")
|
||||
parent.appendChild(a)
|
||||
parent.insertBefore(b, null)
|
||||
|
||||
|
||||
o(parent.childNodes.length).equals(2)
|
||||
o(parent.childNodes[0]).equals(a)
|
||||
o(parent.childNodes[1]).equals(b)
|
||||
|
|
@ -312,81 +312,81 @@ o.spec("domMock", function() {
|
|||
catch (e) {done()}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("setAttribute", function() {
|
||||
o("works", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", "aaa")
|
||||
|
||||
|
||||
o(div.attributes["id"].nodeValue).equals("aaa")
|
||||
o(div.attributes["id"].namespaceURI).equals(null)
|
||||
})
|
||||
o("works w/ number", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", 123)
|
||||
|
||||
|
||||
o(div.attributes["id"].nodeValue).equals("123")
|
||||
})
|
||||
o("works w/ null", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", null)
|
||||
|
||||
|
||||
o(div.attributes["id"].nodeValue).equals("null")
|
||||
})
|
||||
o("works w/ undefined", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", undefined)
|
||||
|
||||
|
||||
o(div.attributes["id"].nodeValue).equals("undefined")
|
||||
})
|
||||
o("works w/ object", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", {})
|
||||
|
||||
|
||||
o(div.attributes["id"].nodeValue).equals("[object Object]")
|
||||
})
|
||||
o("setting via attributes map stringifies", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", "a")
|
||||
div.attributes["id"].nodeValue = 123
|
||||
|
||||
|
||||
o(div.attributes["id"].nodeValue).equals("123")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("setAttributeNS", function() {
|
||||
o("works", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", "aaa")
|
||||
|
||||
|
||||
o(div.attributes["href"].nodeValue).equals("aaa")
|
||||
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||
})
|
||||
o("works w/ number", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", 123)
|
||||
|
||||
|
||||
o(div.attributes["href"].nodeValue).equals("123")
|
||||
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("removeAttribute", function() {
|
||||
o("works", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.setAttribute("id", "aaa")
|
||||
div.removeAttribute("id")
|
||||
|
||||
|
||||
o("id" in div.attributes).equals(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("textContent", function() {
|
||||
o("works", function() {
|
||||
var div = $document.createElement("div")
|
||||
var a = $document.createElement("a")
|
||||
div.textContent = "aaa"
|
||||
|
||||
|
||||
o(div.childNodes.length).equals(1)
|
||||
o(div.firstChild.nodeType).equals(3)
|
||||
o(div.firstChild.nodeValue).equals("aaa")
|
||||
|
|
@ -395,11 +395,11 @@ o.spec("domMock", function() {
|
|||
var div = $document.createElement("div")
|
||||
var a = $document.createElement("a")
|
||||
div.textContent = ""
|
||||
|
||||
|
||||
o(div.childNodes.length).equals(0)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("innerHTML", function() {
|
||||
o("works", function() {
|
||||
var div = $document.createElement("div")
|
||||
|
|
@ -446,7 +446,7 @@ o.spec("domMock", function() {
|
|||
var a = $document.createElement("a")
|
||||
div.appendChild(a)
|
||||
div.innerHTML = "<b></b>"
|
||||
|
||||
|
||||
o(a.parentNode).equals(null)
|
||||
})
|
||||
})
|
||||
|
|
@ -462,22 +462,22 @@ o.spec("domMock", function() {
|
|||
var input = $document.createElement("input")
|
||||
$document.body.appendChild(input)
|
||||
input.focus()
|
||||
|
||||
|
||||
o($document.activeElement).equals(input)
|
||||
|
||||
|
||||
$document.body.removeChild(input)
|
||||
})
|
||||
})
|
||||
o.spec("style", function() {
|
||||
o("has style property", function() {
|
||||
var div = $document.createElement("div")
|
||||
|
||||
|
||||
o(typeof div.style).equals("object")
|
||||
})
|
||||
o("setting style string works", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.style = "background-color: red; border-bottom: 1px solid red;"
|
||||
|
||||
|
||||
o(div.style.backgroundColor).equals("red")
|
||||
o(div.style.borderBottom).equals("1px solid red")
|
||||
})
|
||||
|
|
@ -485,7 +485,7 @@ o.spec("domMock", function() {
|
|||
var div = $document.createElement("div")
|
||||
div.style = "background: red;"
|
||||
div.style = ""
|
||||
|
||||
|
||||
o(div.style.background).equals("")
|
||||
})
|
||||
})
|
||||
|
|
@ -497,17 +497,17 @@ o.spec("domMock", function() {
|
|||
div = $document.createElement("div")
|
||||
e = $document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
|
||||
$document.body.appendChild(div)
|
||||
})
|
||||
o.afterEach(function() {
|
||||
$document.body.removeChild(div)
|
||||
})
|
||||
|
||||
|
||||
o("addEventListener works", function() {
|
||||
div.addEventListener("click", spy, false)
|
||||
div.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.this).equals(div)
|
||||
o(spy.args[0].type).equals("click")
|
||||
|
|
@ -517,14 +517,14 @@ o.spec("domMock", function() {
|
|||
div.addEventListener("click", spy, false)
|
||||
div.removeEventListener("click", spy, false)
|
||||
div.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
done()
|
||||
})
|
||||
o("click fires onclick", function() {
|
||||
div.onclick = spy
|
||||
div.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.this).equals(div)
|
||||
o(spy.args[0].type).equals("click")
|
||||
|
|
@ -542,17 +542,17 @@ o.spec("domMock", function() {
|
|||
div = $document.createElement("div")
|
||||
e = $document.createEvent("HTMLEvents")
|
||||
e.initEvent("transitionend", true, true)
|
||||
|
||||
|
||||
$document.body.appendChild(div)
|
||||
})
|
||||
o.afterEach(function() {
|
||||
$document.body.removeChild(div)
|
||||
})
|
||||
|
||||
|
||||
o("ontransitionend does not fire", function(done) {
|
||||
div.ontransitionend = spy
|
||||
div.dispatchEvent(e)
|
||||
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
done()
|
||||
})
|
||||
|
|
@ -562,21 +562,21 @@ o.spec("domMock", function() {
|
|||
o.spec("a[href]", function() {
|
||||
o("is empty string if no attribute", function() {
|
||||
var a = $document.createElement("a")
|
||||
|
||||
|
||||
o(a.href).equals("")
|
||||
o(a.attributes["href"]).equals(undefined)
|
||||
})
|
||||
o("is path if attribute is set", function() {
|
||||
var a = $document.createElement("a")
|
||||
a.setAttribute("href", "")
|
||||
|
||||
|
||||
o(a.href).notEquals("")
|
||||
o(a.attributes["href"].nodeValue).equals("")
|
||||
})
|
||||
o("is path if property is set", function() {
|
||||
var a = $document.createElement("a")
|
||||
a.href = ""
|
||||
|
||||
|
||||
o(a.href).notEquals("")
|
||||
o(a.attributes["href"].nodeValue).equals("")
|
||||
})
|
||||
|
|
@ -585,24 +585,24 @@ o.spec("domMock", function() {
|
|||
o("only exists in input elements", function() {
|
||||
var input = $document.createElement("input")
|
||||
var a = $document.createElement("a")
|
||||
|
||||
|
||||
o("checked" in input).equals(true)
|
||||
o("checked" in a).equals(false)
|
||||
})
|
||||
o("tracks attribute value when unset", function() {
|
||||
var input = $document.createElement("input")
|
||||
input.setAttribute("type", "checkbox")
|
||||
|
||||
|
||||
o(input.checked).equals(false)
|
||||
o(input.attributes["checked"]).equals(undefined)
|
||||
|
||||
|
||||
input.setAttribute("checked", "")
|
||||
|
||||
|
||||
o(input.checked).equals(true)
|
||||
o(input.attributes["checked"].nodeValue).equals("")
|
||||
|
||||
|
||||
input.removeAttribute("checked")
|
||||
|
||||
|
||||
o(input.checked).equals(false)
|
||||
o(input.attributes["checked"]).equals(undefined)
|
||||
})
|
||||
|
|
@ -610,27 +610,27 @@ o.spec("domMock", function() {
|
|||
var input = $document.createElement("input")
|
||||
input.setAttribute("type", "checkbox")
|
||||
input.checked = true
|
||||
|
||||
|
||||
o(input.checked).equals(true)
|
||||
o(input.attributes["checked"]).equals(undefined)
|
||||
|
||||
|
||||
input.checked = false
|
||||
input.setAttribute("checked", "")
|
||||
|
||||
|
||||
input.checked = true
|
||||
input.removeAttribute("checked")
|
||||
|
||||
|
||||
o(input.checked).equals(true)
|
||||
})
|
||||
o("toggles on click", function() {
|
||||
var input = $document.createElement("input")
|
||||
input.setAttribute("type", "checkbox")
|
||||
input.checked = false
|
||||
|
||||
|
||||
var e = $document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
input.dispatchEvent(e)
|
||||
|
||||
|
||||
o(input.checked).equals(true)
|
||||
})
|
||||
})
|
||||
|
|
@ -638,7 +638,7 @@ o.spec("domMock", function() {
|
|||
o("only exists in input elements", function() {
|
||||
var input = $document.createElement("input")
|
||||
var a = $document.createElement("a")
|
||||
|
||||
|
||||
o("value" in input).equals(true)
|
||||
o("value" in a).equals(false)
|
||||
})
|
||||
|
|
@ -647,14 +647,14 @@ o.spec("domMock", function() {
|
|||
o("reads from child if no value", function() {
|
||||
var input = $document.createElement("textarea")
|
||||
input.appendChild($document.createTextNode("aaa"))
|
||||
|
||||
|
||||
o(input.value).equals("aaa")
|
||||
})
|
||||
o("ignores child if value set", function() {
|
||||
var input = $document.createElement("textarea")
|
||||
input.value = "aaa"
|
||||
input.setAttribute("value", "bbb")
|
||||
|
||||
|
||||
o(input.value).equals("aaa")
|
||||
})
|
||||
})
|
||||
|
|
@ -662,37 +662,37 @@ o.spec("domMock", function() {
|
|||
o("only exist in select elements", function() {
|
||||
var select = $document.createElement("select")
|
||||
var a = $document.createElement("a")
|
||||
|
||||
|
||||
o("value" in select).equals(true)
|
||||
o("value" in a).equals(false)
|
||||
|
||||
|
||||
o("selectedIndex" in select).equals(true)
|
||||
o("selectedIndex" in a).equals(false)
|
||||
})
|
||||
o("value defaults to value at first index", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
o(select.value).equals("a")
|
||||
o(select.selectedIndex).equals(0)
|
||||
})
|
||||
o("value falls back to child nodeValue if no attribute", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.appendChild($document.createTextNode("a"))
|
||||
var option2 = $document.createElement("option")
|
||||
option2.appendChild($document.createTextNode("b"))
|
||||
select.appendChild(option1)
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
o(select.value).equals("a")
|
||||
o(select.selectedIndex).equals(0)
|
||||
o(select.childNodes[0].selected).equals(true)
|
||||
|
|
@ -701,159 +701,159 @@ o.spec("domMock", function() {
|
|||
})
|
||||
o("value defaults to invalid if no options", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
o(select.value).equals("")
|
||||
o(select.selectedIndex).equals(-1)
|
||||
})
|
||||
o("setting valid value works", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.value = "b"
|
||||
|
||||
|
||||
o(select.value).equals("b")
|
||||
o(select.selectedIndex).equals(1)
|
||||
})
|
||||
o("setting valid value works with optgroup", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
|
||||
|
||||
var option3 = $document.createElement("option")
|
||||
option3.setAttribute("value", "c")
|
||||
|
||||
|
||||
var optgroup = $document.createElement("optgroup")
|
||||
optgroup.appendChild(option1)
|
||||
optgroup.appendChild(option2)
|
||||
select.appendChild(optgroup)
|
||||
select.appendChild(option3)
|
||||
|
||||
|
||||
select.value = "b"
|
||||
|
||||
|
||||
o(select.value).equals("b")
|
||||
o(select.selectedIndex).equals(1)
|
||||
})
|
||||
o("setting valid selectedIndex works", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.selectedIndex = 1
|
||||
|
||||
|
||||
o(select.value).equals("b")
|
||||
o(select.selectedIndex).equals(1)
|
||||
})
|
||||
o("setting option[selected] works", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.childNodes[1].selected = true
|
||||
|
||||
|
||||
o(select.value).equals("b")
|
||||
o(select.selectedIndex).equals(1)
|
||||
})
|
||||
o("unsetting option[selected] works", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.childNodes[1].selected = true
|
||||
select.childNodes[1].selected = false
|
||||
|
||||
|
||||
o(select.value).equals("a")
|
||||
o(select.selectedIndex).equals(0)
|
||||
})
|
||||
o("setting invalid value yields a selectedIndex of -1 and value of empty string", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.value = "c"
|
||||
|
||||
|
||||
o(select.value).equals("")
|
||||
o(select.selectedIndex).equals(-1)
|
||||
})
|
||||
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "b")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.selectedIndex = -2
|
||||
|
||||
|
||||
o(select.value).equals("")
|
||||
o(select.selectedIndex).equals(-1)
|
||||
})
|
||||
o("setting invalid value yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.value = "c"
|
||||
|
||||
|
||||
o(select.value).equals("")
|
||||
o(select.selectedIndex).equals(-1)
|
||||
})
|
||||
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
|
||||
var select = $document.createElement("select")
|
||||
|
||||
|
||||
var option1 = $document.createElement("option")
|
||||
option1.setAttribute("value", "a")
|
||||
select.appendChild(option1)
|
||||
|
||||
|
||||
var option2 = $document.createElement("option")
|
||||
option2.setAttribute("value", "")
|
||||
select.appendChild(option2)
|
||||
|
||||
|
||||
select.selectedIndex = -2
|
||||
|
||||
|
||||
o(select.value).equals("")
|
||||
o(select.selectedIndex).equals(-1)
|
||||
})
|
||||
|
|
@ -863,7 +863,7 @@ o.spec("domMock", function() {
|
|||
o("works", function() {
|
||||
var el = $document.createElement("div")
|
||||
el.className = "a"
|
||||
|
||||
|
||||
o(el.className).equals("a")
|
||||
o(el.attributes["class"].nodeValue).equals("a")
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ var parseURL = require("../../test-utils/parseURL")
|
|||
|
||||
o.spec("parseURL", function() {
|
||||
var root = {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}
|
||||
|
||||
|
||||
o.spec("full URL", function() {
|
||||
o("parses full URL", function() {
|
||||
var data = parseURL("http://www.google.com:80/test?a=b#c")
|
||||
|
|
@ -147,4 +147,4 @@ o.spec("parseURL", function() {
|
|||
o(data.pathname).equals("/a:b")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,30 +4,30 @@ var o = require("../../ospec/ospec")
|
|||
var pushStateMock = require("../../test-utils/pushStateMock")
|
||||
|
||||
o.spec("pushStateMock", function() {
|
||||
|
||||
|
||||
var $window
|
||||
o.beforeEach(function() {
|
||||
$window = pushStateMock()
|
||||
})
|
||||
|
||||
|
||||
o.spec("initial state", function() {
|
||||
o("has url on page load", function() {
|
||||
o($window.location.href).equals("http://localhost/")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.spec("set href", function() {
|
||||
o("changes url on location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "http://localhost/a"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a")
|
||||
})
|
||||
o("changes url on relative location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "a"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a")
|
||||
o($window.location.pathname).equals("/a")
|
||||
|
|
@ -36,7 +36,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.location.href = "a"
|
||||
var old = $window.location.href
|
||||
$window.location.href = ".."
|
||||
|
||||
|
||||
o(old).equals("http://localhost/a")
|
||||
o($window.location.href).equals("http://localhost/")
|
||||
o($window.location.pathname).equals("/")
|
||||
|
|
@ -45,7 +45,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.location.href = "a/b/c"
|
||||
var old = $window.location.href
|
||||
$window.location.href = ".."
|
||||
|
||||
|
||||
o(old).equals("http://localhost/a/b/c")
|
||||
o($window.location.href).equals("http://localhost/a")
|
||||
o($window.location.pathname).equals("/a")
|
||||
|
|
@ -53,7 +53,7 @@ o.spec("pushStateMock", function() {
|
|||
o("does not change url on dotdot location.href change from root", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = ".."
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/")
|
||||
o($window.location.pathname).equals("/")
|
||||
|
|
@ -62,7 +62,7 @@ o.spec("pushStateMock", function() {
|
|||
var old = $window.location.href
|
||||
$window.location.href = "a"
|
||||
$window.location.href = "./b"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/b")
|
||||
o($window.location.pathname).equals("/b")
|
||||
|
|
@ -71,7 +71,7 @@ o.spec("pushStateMock", function() {
|
|||
var old = $window.location.href
|
||||
$window.location.href = "a"
|
||||
$window.location.href = "."
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a")
|
||||
o($window.location.pathname).equals("/a")
|
||||
|
|
@ -79,7 +79,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes url on hash-only location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "#a"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/#a")
|
||||
o($window.location.hash).equals("#a")
|
||||
|
|
@ -87,7 +87,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes url on search-only location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "?a"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/?a")
|
||||
o($window.location.search).equals("?a")
|
||||
|
|
@ -95,7 +95,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes hash on location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "http://localhost/a#b"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a#b")
|
||||
o($window.location.hash).equals("#b")
|
||||
|
|
@ -103,7 +103,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes search on location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "http://localhost/a?b"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a?b")
|
||||
o($window.location.search).equals("?b")
|
||||
|
|
@ -111,7 +111,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes search and hash on location.href change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "http://localhost/a?b#c"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a?b#c")
|
||||
o($window.location.search).equals("?b")
|
||||
|
|
@ -120,7 +120,7 @@ o.spec("pushStateMock", function() {
|
|||
o("handles search with search and hash", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "http://localhost/a?b?c#d"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a?b?c#d")
|
||||
o($window.location.search).equals("?b?c")
|
||||
|
|
@ -129,7 +129,7 @@ o.spec("pushStateMock", function() {
|
|||
o("handles hash with search and hash", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.href = "http://localhost/a#b?c#d"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a#b?c#d")
|
||||
o($window.location.search).equals("")
|
||||
|
|
@ -140,7 +140,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes url on location.search change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.search = "?b"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/?b")
|
||||
o($window.location.search).equals("?b")
|
||||
|
|
@ -150,7 +150,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes url on location.hash change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.hash = "#b"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/#b")
|
||||
o($window.location.hash).equals("#b")
|
||||
|
|
@ -160,7 +160,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes url on location.pathname change", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.pathname = "/a"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a")
|
||||
o($window.location.pathname).equals("/a")
|
||||
|
|
@ -181,7 +181,7 @@ o.spec("pushStateMock", function() {
|
|||
o("setting origin changes href", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.port = "81"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.port).equals("81")
|
||||
o($window.location.href).equals("http://localhost:81/")
|
||||
|
|
@ -191,7 +191,7 @@ o.spec("pushStateMock", function() {
|
|||
o("setting hostname changes href", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.hostname = "127.0.0.1"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.hostname).equals("127.0.0.1")
|
||||
o($window.location.href).equals("http://127.0.0.1/")
|
||||
|
|
@ -201,7 +201,7 @@ o.spec("pushStateMock", function() {
|
|||
o("setting origin is ignored", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.origin = "http://127.0.0.1"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.origin).equals("http://localhost")
|
||||
})
|
||||
|
|
@ -210,7 +210,7 @@ o.spec("pushStateMock", function() {
|
|||
o("setting host is ignored", function() {
|
||||
var old = $window.location.href
|
||||
$window.location.host = "http://127.0.0.1"
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.host).equals("localhost")
|
||||
})
|
||||
|
|
@ -219,14 +219,14 @@ o.spec("pushStateMock", function() {
|
|||
o("changes url on pushstate", function() {
|
||||
var old = $window.location.href
|
||||
$window.history.pushState(null, null, "http://localhost/a")
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/a")
|
||||
})
|
||||
o("changes search on pushstate", function() {
|
||||
var old = $window.location.href
|
||||
$window.history.pushState(null, null, "http://localhost/?a")
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/?a")
|
||||
o($window.location.search).equals("?a")
|
||||
|
|
@ -234,7 +234,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes search on relative pushstate", function() {
|
||||
var old = $window.location.href
|
||||
$window.history.pushState(null, null, "?a")
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/?a")
|
||||
o($window.location.search).equals("?a")
|
||||
|
|
@ -242,7 +242,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes hash on pushstate", function() {
|
||||
var old = $window.location.href
|
||||
$window.history.pushState(null, null, "http://localhost/#a")
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/#a")
|
||||
o($window.location.hash).equals("#a")
|
||||
|
|
@ -250,7 +250,7 @@ o.spec("pushStateMock", function() {
|
|||
o("changes hash on relative pushstate", function() {
|
||||
var old = $window.location.href
|
||||
$window.history.pushState(null, null, "#a")
|
||||
|
||||
|
||||
o(old).equals("http://localhost/")
|
||||
o($window.location.href).equals("http://localhost/#a")
|
||||
o($window.location.hash).equals("#a")
|
||||
|
|
@ -260,14 +260,14 @@ o.spec("pushStateMock", function() {
|
|||
o("history.back() without history does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history.back() after pushstate triggers onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.pushState(null, null, "http://localhost/a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(1)
|
||||
o($window.onpopstate.args[0].type).equals("popstate")
|
||||
})
|
||||
|
|
@ -275,63 +275,63 @@ o.spec("pushStateMock", function() {
|
|||
$window.onpopstate = o.spy()
|
||||
$window.history.pushState(null, null, "a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(1)
|
||||
})
|
||||
o("history.back() after search pushstate triggers onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.pushState(null, null, "http://localhost/?a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(1)
|
||||
})
|
||||
o("history.back() after relative search pushstate triggers onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.pushState(null, null, "?a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(1)
|
||||
})
|
||||
o("history.back() after hash pushstate triggers onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.pushState(null, null, "http://localhost/#a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(1)
|
||||
})
|
||||
o("history.back() after relative hash pushstate triggers onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.pushState(null, null, "#a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(1)
|
||||
})
|
||||
o("history.back() after replacestate does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.replaceState(null, null, "http://localhost/a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history.back() after relative replacestate does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.replaceState(null, null, "a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history.back() after relative search replacestate does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.replaceState(null, null, "?a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history.back() after relative hash replacestate does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.replaceState(null, null, "#a")
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history.forward() after pushstate triggers onpopstate", function() {
|
||||
|
|
@ -339,7 +339,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.pushState(null, null, "http://localhost/a")
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(2)
|
||||
})
|
||||
o("history.forward() after relative pushstate triggers onpopstate", function() {
|
||||
|
|
@ -347,7 +347,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.pushState(null, null, "a")
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(2)
|
||||
})
|
||||
o("history.forward() after search pushstate triggers onpopstate", function() {
|
||||
|
|
@ -355,7 +355,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.pushState(null, null, "http://localhost/?a")
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(2)
|
||||
})
|
||||
o("history.forward() after relative search pushstate triggers onpopstate", function() {
|
||||
|
|
@ -363,7 +363,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.pushState(null, null, "?a")
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(2)
|
||||
})
|
||||
o("history.forward() after hash pushstate triggers onpopstate", function() {
|
||||
|
|
@ -371,7 +371,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.pushState(null, null, "http://localhost/#a")
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(2)
|
||||
})
|
||||
o("history.forward() after relative hash pushstate triggers onpopstate", function() {
|
||||
|
|
@ -379,33 +379,33 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.pushState(null, null, "#a")
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(2)
|
||||
})
|
||||
o("history.back() without history does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history.forward() without history does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("history navigation without history does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("reverse history navigation without history does not trigger onpopstate", function() {
|
||||
$window.onpopstate = o.spy()
|
||||
$window.history.forward()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onpopstate.callCount).equals(0)
|
||||
})
|
||||
o("onpopstate has correct url during call", function(done) {
|
||||
|
|
@ -422,47 +422,47 @@ o.spec("pushStateMock", function() {
|
|||
o("onhashchange triggers on location.href change", function() {
|
||||
$window.onhashchange = o.spy()
|
||||
$window.location.href = "http://localhost/#a"
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(1)
|
||||
o($window.onhashchange.args[0].type).equals("hashchange")
|
||||
})
|
||||
o("onhashchange triggers on relative location.href change", function() {
|
||||
$window.onhashchange = o.spy()
|
||||
$window.location.href = "#a"
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(1)
|
||||
})
|
||||
o("onhashchange triggers on location.hash change", function() {
|
||||
$window.onhashchange = o.spy()
|
||||
$window.location.hash = "#a"
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(1)
|
||||
})
|
||||
o("onhashchange does not trigger on page change", function() {
|
||||
$window.onhashchange = o.spy()
|
||||
$window.location.href = "http://localhost/a"
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
o("onhashchange does not trigger on page change with different hash", function() {
|
||||
$window.location.href = "http://localhost/#a"
|
||||
$window.onhashchange = o.spy()
|
||||
$window.location.href = "http://localhost/a#b"
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
o("onhashchange does not trigger on page change with same hash", function() {
|
||||
$window.location.href = "http://localhost/#b"
|
||||
$window.onhashchange = o.spy()
|
||||
$window.location.href = "http://localhost/a#b"
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
o("onhashchange triggers on history.back()", function() {
|
||||
$window.location.href = "#a"
|
||||
$window.onhashchange = o.spy()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(1)
|
||||
})
|
||||
o("onhashchange triggers on history.forward()", function() {
|
||||
|
|
@ -470,7 +470,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.onhashchange = o.spy()
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(2)
|
||||
})
|
||||
o("onhashchange does not trigger on history.back() that causes page change with different hash", function() {
|
||||
|
|
@ -478,7 +478,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.location.href = "a#b"
|
||||
$window.onhashchange = o.spy()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
o("onhashchange does not trigger on history.back() that causes page change with same hash", function() {
|
||||
|
|
@ -486,7 +486,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.location.href = "a#a"
|
||||
$window.onhashchange = o.spy()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
o("onhashchange does not trigger on history.forward() that causes page change with different hash", function() {
|
||||
|
|
@ -495,7 +495,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.onhashchange = o.spy()
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
o("onhashchange does not trigger on history.forward() that causes page change with same hash", function() {
|
||||
|
|
@ -504,7 +504,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.onhashchange = o.spy()
|
||||
$window.history.back()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onhashchange.callCount).equals(0)
|
||||
})
|
||||
})
|
||||
|
|
@ -512,45 +512,45 @@ o.spec("pushStateMock", function() {
|
|||
o("onunload triggers on location.href change", function() {
|
||||
$window.onunload = o.spy()
|
||||
$window.location.href = "http://localhost/a"
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(1)
|
||||
o($window.onunload.args[0].type).equals("unload")
|
||||
})
|
||||
o("onunload triggers on relative location.href change", function() {
|
||||
$window.onunload = o.spy()
|
||||
$window.location.href = "a"
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(1)
|
||||
})
|
||||
o("onunload triggers on search change via location.href", function() {
|
||||
$window.onunload = o.spy()
|
||||
$window.location.href = "http://localhost/?a"
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(1)
|
||||
})
|
||||
o("onunload triggers on relative search change via location.href", function() {
|
||||
$window.onunload = o.spy()
|
||||
$window.location.href = "?a"
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(1)
|
||||
})
|
||||
o("onunload does not trigger on hash change via location.href", function() {
|
||||
$window.onunload = o.spy()
|
||||
$window.location.href = "http://localhost/#a"
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(0)
|
||||
})
|
||||
o("onunload does not trigger on relative hash change via location.href", function() {
|
||||
$window.onunload = o.spy()
|
||||
$window.location.href = "#a"
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(0)
|
||||
})
|
||||
o("onunload does not trigger on hash-only history.back()", function() {
|
||||
$window.location.href = "#a"
|
||||
$window.onunload = o.spy()
|
||||
$window.history.back()
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(0)
|
||||
})
|
||||
o("onunload does not trigger on hash-only history.forward()", function() {
|
||||
|
|
@ -558,7 +558,7 @@ o.spec("pushStateMock", function() {
|
|||
$window.history.back()
|
||||
$window.onunload = o.spy()
|
||||
$window.history.forward()
|
||||
|
||||
|
||||
o($window.onunload.callCount).equals(0)
|
||||
})
|
||||
o("onunload has correct url during call via location.href change", function(done) {
|
||||
|
|
@ -576,4 +576,4 @@ o.spec("pushStateMock", function() {
|
|||
$window.location.search = "?a"
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ o.spec("xhrMock", function() {
|
|||
o.beforeEach(function() {
|
||||
$window = xhrMock()
|
||||
})
|
||||
|
||||
|
||||
o.spec("xhr", function() {
|
||||
o("works", function(done, timeout) {
|
||||
$window.$defineRoutes({
|
||||
|
|
@ -81,13 +81,13 @@ o.spec("xhrMock", function() {
|
|||
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 1}) + ")"}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
$window["cb"] = finish
|
||||
|
||||
|
||||
var script = $window.document.createElement("script")
|
||||
script.src = "/test?callback=cb"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
|
||||
function finish(data) {
|
||||
o(data).deepEquals({a: 1})
|
||||
done()
|
||||
|
|
@ -101,13 +101,13 @@ o.spec("xhrMock", function() {
|
|||
}
|
||||
})
|
||||
$window.$defineJSONPCallbackKey("cb")
|
||||
|
||||
|
||||
$window["customcb"] = finish2
|
||||
|
||||
|
||||
var script = $window.document.createElement("script")
|
||||
script.src = "/test?cb=customcb"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
|
||||
function finish2(data) {
|
||||
o(data).deepEquals({a: 2})
|
||||
done()
|
||||
|
|
@ -120,13 +120,13 @@ o.spec("xhrMock", function() {
|
|||
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 3}) + ")"}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
$window["cbwithinparams"] = finish
|
||||
|
||||
|
||||
var script = $window.document.createElement("script")
|
||||
script.src = "/test?a=b&callback=cbwithinparams&c=d"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
|
||||
function finish(data) {
|
||||
o(data).deepEquals({a: 3})
|
||||
done()
|
||||
|
|
@ -137,11 +137,11 @@ o.spec("xhrMock", function() {
|
|||
script.onerror = finish
|
||||
script.src = "/test?cb=nonexistent"
|
||||
$window.document.documentElement.appendChild(script)
|
||||
|
||||
|
||||
function finish(e) {
|
||||
o(e.type).equals("error")
|
||||
done()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ module.exports = function() {
|
|||
var serverErrorHandler = function() {
|
||||
return {status: 500, responseText: "server error, most likely the URL was not defined"}
|
||||
}
|
||||
|
||||
|
||||
var $window = {
|
||||
XMLHttpRequest: function XMLHttpRequest() {
|
||||
var args = {}
|
||||
|
|
@ -74,4 +74,4 @@ module.exports = function() {
|
|||
},
|
||||
}
|
||||
return $window
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ module.exports = function(store) {
|
|||
if (arguments.length > 0) store = arguments[0]
|
||||
return store
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<script src="../../util/withAttr.js"></script>
|
||||
<script src="test-prop.js"></script>
|
||||
<script src="test-withAttr.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ o.spec("prop", function() {
|
|||
var initialValue = store()
|
||||
store(2)
|
||||
var newValue = store()
|
||||
|
||||
|
||||
o(initialValue).equals(1)
|
||||
o(newValue).equals(2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ o.spec("withAttr", function() {
|
|||
handler: withAttr("value", spy)
|
||||
}
|
||||
context.handler({currentTarget: {value: 1}})
|
||||
|
||||
|
||||
o(spy.args).deepEquals([1])
|
||||
o(spy.this).equals(context)
|
||||
})
|
||||
|
|
@ -23,7 +23,7 @@ o.spec("withAttr", function() {
|
|||
handler: withAttr("readonly", spy)
|
||||
}
|
||||
context.handler({currentTarget: target})
|
||||
|
||||
|
||||
o(spy.args).deepEquals(["readonly"])
|
||||
o(spy.this).equals(context)
|
||||
})
|
||||
|
|
@ -32,7 +32,7 @@ o.spec("withAttr", function() {
|
|||
var context = {}
|
||||
var handler = withAttr("value", spy, context)
|
||||
handler({currentTarget: {value: 1}})
|
||||
|
||||
|
||||
o(spy.this).equals(context)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@ module.exports = function(attrName, callback, context) {
|
|||
return function(e) {
|
||||
return callback.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue