Skip to content

Instantly share code, notes, and snippets.

@jamesbirtles
Last active January 15, 2018 16:01
Show Gist options
  • Save jamesbirtles/95be0eabe66ab4a0c57457e242344f48 to your computer and use it in GitHub Desktop.
Save jamesbirtles/95be0eabe66ab4a0c57457e242344f48 to your computer and use it in GitHub Desktop.
svelte boolean attributes
"use strict";
function data() {
return {
disabled: false,
};
};
var Buttons = {};
Buttons.filename = "Buttons.html";
Buttons.data = function() {
return data();
};
Buttons.render = function(state, options = {}) {
var components = new Set();
function addComponent(component) {
components.add(component);
}
var result = { head: '', addComponent };
var html = Buttons._render(result, state, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
return {
html,
head: result.head,
css: { code: cssCode, map: null },
toString() {
return html;
}
};
}
Buttons._render = function(__result, state, options) {
__result.addComponent(Buttons);
state = Object.assign(data(), state);
return `<button disabled="${state.disabled}">Hello</button>
<button disabled="${state.disabled}">Hello</button>
<button>Hello</button>`;
};
Buttons.css = {
code: '',
map: null
};
var warned = false;
Buttons.renderCss = function() {
if (!warned) {
console.error('Component.renderCss(...) is deprecated and will be removed in v2 — use Component.render(...).css instead');
warned = true;
}
var components = [];
return {
css: components.map(x => x.css).join('\n'),
map: null,
components
};
};
module.exports = Buttons;
<button :disabled>Hello</button>
<button disabled="{{disabled}}">Hello</button>
<button>Hello</button>
<script>
export default {
data() {
return {
disabled: false,
};
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment