Comparing version 0.0.2 to 1.1.0
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.kontainer = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
exports.create=function(e){var r,o,t;if("string"==typeof e)o=e;else{if(!o)throw new Error("Target must be set");t=e}return function(e,n){var i;if(o){if(i=document.querySelector(o),!i)throw new Error("No container at "+o)}else i=t;if(ko.cleanNode(i),i.innerHTML="",r&&"function"==typeof r.dispose)try{r.dispose()}catch(s){console.log(s),console.error(s.stack)}if("string"==typeof e)i.innerHTML=e;else{if(!e)throw new Error("Template is not set");i.appendChild(e)}ko.applyBindings(n,i),r=n}}; | ||
function call(e,r,n){if("function"==typeof e[r])try{e[r](n)}catch(o){console.log(o),o.stack&&console.error(o.stack)}}exports.create=function(e){var r,n,o;if("string"==typeof e)n=e;else{if(!n)throw new Error("Target must be set");o=e}return function(e,t){var i;if(n){if(i=document.querySelector(n),!i)throw new Error("No container at "+n)}else i=o;if(ko.cleanNode(i),i.innerHTML="",r&&call(r,"dispose",i),"string"==typeof e)i.innerHTML=e;else{if(!e)throw new Error("Template is not set");i.appendChild(e)}call(t,"inserted",i),ko.applyBindings(t,i),r=t,call(t,"bound",i)}}; | ||
},{}]},{},[1])(1) | ||
}); |
@@ -62,13 +62,5 @@ // Creates view object bound to | ||
if (last && typeof last.dispose === 'function') { | ||
if (last) { | ||
try { | ||
last.dispose(); | ||
} catch (e) { | ||
console.log(e); | ||
console.error(e.stack); | ||
} | ||
call(last, 'dispose', container); | ||
} | ||
@@ -93,2 +85,6 @@ | ||
// Call 'inserted' callback. | ||
call(model, 'inserted', container); | ||
// Apply bindings. | ||
@@ -101,3 +97,30 @@ | ||
last = model; | ||
// Calls 'bound' callback. | ||
call(model, 'bound', container); | ||
}; | ||
}; | ||
// Calls given method if exists. | ||
// Catches possible exceptions. | ||
function call(base, name, argument) { | ||
if (typeof base[name] === 'function') { | ||
try { | ||
base[name](argument); | ||
} catch (e) { | ||
console.log(e); | ||
if (e.stack) { | ||
console.error(e.stack); | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "kontainer", | ||
"version": "0.0.2", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Raivo Laanemets", |
@@ -17,5 +17,15 @@ # kontainer | ||
can be either a DOM element/document fragment or a string. Unbinds | ||
previously set viewModel. If the old viewModel had `dispose()` method | ||
then it is executed. | ||
previously set viewModel. | ||
### Lifecycle callbacks | ||
The viewModel can have the following methods defined: | ||
* `inserted(DOM target)` - called when the template is inserted into the DOM tree. | ||
* `bound(DOM target)` - called when the viewModel is bound to the DOM tree. | ||
* `dispose(DOM target)` - called when the template and the viewModel are replaced. | ||
The `inserted` callback is called before `bound` as the template is | ||
inserted into the DOM tree before the bindings are applied. | ||
## Example | ||
@@ -22,0 +32,0 @@ |
@@ -12,3 +12,3 @@ casper.test.begin('Page switching', function suite(test) { | ||
casper.test.assertSelectorHasText('#page span', 'Hello World!'); | ||
test.assertSelectorHasText('#page span', 'Hello World!'); | ||
}); | ||
@@ -20,5 +20,50 @@ | ||
casper.test.assertSelectorHasText('#page span', 'Hello from Page 2'); | ||
test.assertSelectorHasText('#page span', 'Hello from Page 2'); | ||
}); | ||
casper.thenClick('#link-page-3'); | ||
casper.then(function() { | ||
test.assertSelectorHasText('#page span', 'Hello from Page 3'); | ||
var boundCalled = casper.evaluate(function() { | ||
return boundCalled; | ||
}); | ||
test.assertEquals(boundCalled, 1); | ||
var insertedCalled = casper.evaluate(function() { | ||
return insertedCalled; | ||
}); | ||
test.assertEquals(insertedCalled, 1); | ||
var disposeCalled = casper.evaluate(function() { | ||
return disposeCalled; | ||
}); | ||
test.assertEquals(disposeCalled, 0); | ||
}); | ||
casper.thenClick('#link-page-2'); | ||
casper.then(function() { | ||
test.assertSelectorHasText('#page span', 'Hello from Page 2'); | ||
}); | ||
casper.then(function() { | ||
var disposeCalled = casper.evaluate(function() { | ||
return disposeCalled; | ||
}); | ||
test.assertEquals(disposeCalled, 1); | ||
}); | ||
casper.run(function() { | ||
@@ -25,0 +70,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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11309
119
2
70