Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@dvo/stamp", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Tool for lightweight componentization.", | ||
@@ -5,0 +5,0 @@ "main": "stamp.js", |
@@ -85,3 +85,3 @@ # STAMP | ||
- `stamp()` Creates the component from the template, mutates it and appends to the target (by default, the template's container). | ||
- `stamp()` <small>:function</small> Creates the component from the template, mutates it and appends to the target (by default, the template's container). If an argument function is passed, it will be run against the element *after* it is appended. | ||
- `alias()` <small>:string</small> Give the current stamp an alias, so it's easy to retrieve it later by calling `Stamp.get(alias)`. | ||
@@ -88,0 +88,0 @@ - `change()` <small>:function</small> Defines a mutator function to be called just before stamping. The function receives the component instance **before** it is appended to the DOM, so manipulations on it are cheaper and you don't get FOUC. |
20
stamp.js
const stampData = {} | ||
const aliasData = {} | ||
window.$$ = [ | ||
stampData, | ||
aliasData | ||
] | ||
const identity = x => x | ||
@@ -13,3 +9,2 @@ | ||
this.template = document.querySelector(selector) | ||
// this.targetSelector = null | ||
this.target = this.template.parentElement | ||
@@ -25,3 +20,2 @@ this.cap = Infinity | ||
function Stamp (selector) { | ||
@@ -52,5 +46,6 @@ let data = {} | ||
}, | ||
stamp () { | ||
stamp (callback) { | ||
console.log('?', !!callback) | ||
if (count() < data.cap) { | ||
console.log('!!', count(), data.cap) | ||
const target = data.target | ||
const clone = data.template.content.cloneNode(true) | ||
@@ -60,3 +55,7 @@ const cloneContent = clone.firstElementChild | ||
cloneContent.setAttribute('data-_stamp', data.selector) | ||
data.target.append(clone) | ||
target.append(clone) | ||
if (callback) { | ||
console.log('cbk', callback, target.lastElementChild) | ||
callback(target.lastElementChild) | ||
} | ||
} | ||
@@ -74,3 +73,2 @@ return this | ||
target (targetSelector) { | ||
// data.targetSelector = targetSelector | ||
data.target = document.querySelector(targetSelector) | ||
@@ -104,3 +102,3 @@ return this | ||
debug () { | ||
console.log('stamp data:', data) | ||
console.debug('stamp data:', data) | ||
return this | ||
@@ -107,0 +105,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9171
96