diff --git a/skooma.js b/skooma.js index 53b88e8..e3d8ef3 100644 --- a/skooma.js +++ b/skooma.js @@ -83,5 +83,7 @@ const nameSpacedProxy = (options={}) => new Proxy(Window, { has: (target, prop) => true, }) +export const handle = fn => event => { event.preventDefault(); return fn(event) } + export const html = nameSpacedProxy({nameFilter: name => name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}) export const svg = nameSpacedProxy({xmlns: "http://www.w3.org/2000/svg"}) diff --git a/skooma.md b/skooma.md index c825da1..ff0ca43 100644 --- a/skooma.md +++ b/skooma.md @@ -35,15 +35,21 @@ html.div({foo: "bar"}, {foo: false}) // Special keys: -html.div(dataset: {foo: 1, bar: 2}) -// Creates a
with the attributes "data-foo" and "data-bar" set to 1 and 2 -html.div(style: {color: 'red'}) -// Creates a
with the "style" attribute set to "color: red" +html.div(dataset: {foo: 1, bar: 2}) // Creates a
with the attributes "data-foo" and "data-bar" set to 1 and 2 html.div(style: {color: 'red'}) // Creates a
with the "style" attribute set to "color: red" ``` Generators can be called with many arguments. Arrays get iterated recursively as if they were part of a flat argument list. +## handle + +Since it is common for event handlers to call `preventDefault()`, skooma +provides a helper function called `handle` with the following definition: + +```js +fn => event => { event.preventDefault(); return fn(event) } +``` + ## A few more examples: Create a Button that deletes itself: