Comparing version 1.2.1 to 1.2.2
@@ -48,4 +48,3 @@ // overlap | ||
if( content != this.nContent && | ||
content != this.cContent ) { | ||
if( content != this.nContent && content != this.cContent ) { | ||
@@ -60,3 +59,2 @@ if( this.nContent && this.nContent.destroy ) | ||
content.init( this.data, this.swap.bind( this, this.nContent, onComplete ) ); | ||
} else { | ||
@@ -63,0 +61,0 @@ |
{ | ||
"name": "bw-vm", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "This is a view manager for bigwheel (it brings in out content)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "tape test/*.js" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/8..latest", | ||
"chrome/31..latest", | ||
"firefox/33..latest", | ||
"safari/6..latest", | ||
"opera/11.0..latest", | ||
"iphone/6..latest", | ||
"ipad/6..latest", | ||
"android-browser/4.2..latest" | ||
] | ||
}, | ||
"repository": { | ||
@@ -25,3 +38,6 @@ "type": "git", | ||
"homepage": "https://github.com/MikkoH/bw-vm", | ||
"dependencies": {} | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"tape": "^3.0.3" | ||
} | ||
} |
@@ -1,7 +0,22 @@ | ||
bw-vm | ||
===== | ||
# bw-vm | ||
This is a view manager for bigwheel (it brings in out content) | ||
[![browser support](https://ci.testling.com/bigwheel-framework/bw-vm.png) | ||
](https://ci.testling.com/bigwheel-framework/bw-vm) | ||
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges) | ||
`bw-vm` is a view manager. It's main purpose is to bring in and take out views/sections. | ||
`bw-vm` has no ties to the browser and so can be used in environments that have no ties to the browser. | ||
For instance you could use it in a command line application or [cocoonjs](https://www.ludei.com/cocoonjs/). | ||
Views/sections are objects which may have the functions `init`, `resize`, `aniIn`, `aniOut`, `destroy` defined. | ||
`bw-vm` will call those functions in sequence `init`, `resize`, `aniIn`, `aniOut`, `destroy`. `aniOut` and `destroy` | ||
will not be called until the next view/section comes in. | ||
## Usage | ||
[![NPM](https://nodei.co/npm/bw-vm.png)](https://www.npmjs.com/package/bw-vm) | ||
### Example | ||
@@ -11,11 +26,62 @@ ```javascript | ||
var section = require( './yourSection' ); // your section might have init, aniIn, aniOut, destroy, resize | ||
var someDataYouMightWantToPass = { | ||
var optionalDataYouCanPass = { | ||
imgUrl: './someImage.jpg' | ||
someData: './someImage.jpg' | ||
}; | ||
var ifYouWantToKnowWhenTheSectionIsIn = function() {}; | ||
var optionalCallbackForWhenSectionIsIn = function() {}; | ||
viewmanager.show( section, someDataYouMightWantToPass, ifYouWantToKnowWhenTheSectionIsIn ); | ||
var section1 = new Section(); // section 1 will be the initial view | ||
var section2 = new Section(); // section 2 will be the second view | ||
viewmanager.show( section1, optionalDataYouCanPass, optionalCallbackForWhenSectionIsIn ); | ||
viewmanager.show( section2 ); // will take out the first section and bring in the second | ||
function Section() {}; | ||
Section.prototype = { | ||
init: function( data, done ) { | ||
// data == optionalCallbackForWhenSectionIsIn | ||
done(); // call done to ensure the viewmanager knows initialization is done | ||
}, | ||
resize: function( width, height ) { | ||
// there is a function on the view manager which can be called to resize | ||
// current section it's holding. | ||
// by default 980x570 is passed | ||
}, | ||
aniIn: function( data, done ) { | ||
// data == optionalCallbackForWhenSectionIsIn | ||
done(); // call done to ensure the viewmanager knows animate in is done | ||
}, | ||
aniOut: function( data, done ) { | ||
// data == is the data used to bring in the next section | ||
done(); // call done to ensure the viewmanager knows animate out is done | ||
}, | ||
destroy: function( data, done ) { | ||
// data == is the data used to bring in the next section | ||
done(); // call done to ensure the viewmanager knows when destrou is done | ||
} | ||
}; | ||
``` | ||
## License | ||
MIT, see [LICENSE.md](http://github.com/mikkoh/bw-vm/blob/master/LICENSE.md) for details. |
var vm = require( '../' ); | ||
var test = require( 'tape' ); | ||
var DURATION_INI = 30, | ||
DURATION_ANI = 1000; | ||
setTimeout( function() {}, 1000 ); | ||
var Content = { | ||
var manager = vm(); | ||
var idxText = 0; | ||
var t; | ||
var passedData = { thisWorks: true }; | ||
var section5; | ||
init: function( data, onComplete ) { | ||
var section = function( name ) { | ||
if( onComplete == undefined ) | ||
onComplete = data; | ||
this.name = name; | ||
}; | ||
console.log( ( Date.now() - this.startTime ), 'init', this.name ); | ||
console.log( 'model data', data ); | ||
section.prototype = { | ||
setTimeout( onComplete, DURATION_INI ); | ||
init: function( req, done ) { | ||
switch( idxText ) { | ||
case 1: | ||
t.equal( this.name, 'section 1', 'section 1 init' ); | ||
t.equal( req, passedData, 'passed data' ); | ||
done(); | ||
break; | ||
case 3: | ||
t.equal( this.name, 'section 2', 'section 2 init' ); | ||
done(); | ||
break; | ||
case 6: | ||
t.equal( this.name, 'section 5', 'section 5 init' ); | ||
done(); | ||
nextTest(); | ||
break; | ||
case 7: | ||
t.fail( 'Allowed bringing in a duplicate section' ); | ||
done(); | ||
break; | ||
} | ||
}, | ||
resize: function( w, h ) { | ||
resize: function( width, height ) { | ||
console.log( ( Date.now() - this.startTime ), 'resize', this.name, w, h ); | ||
switch( idxText ) { | ||
case 1: | ||
t.equal( width, 980, 'width is set to default' ); | ||
t.equal( height, 570, 'height is set to default' ); | ||
break; | ||
case 2: | ||
t.equal( width, 333, 'width is correct after resize' ); | ||
t.equal( height, 33, 'height is correct after resize' ); | ||
nextTest(); | ||
break; | ||
} | ||
}, | ||
aniIn: function( onComplete ) { | ||
aniIn: function( req, done ) { | ||
switch( idxText ) { | ||
console.log( ( Date.now() - this.startTime ), 'aniIn', this.name ); | ||
case 1: | ||
t.equal( this.name, 'section 1', 'section 1 aniIn' ); | ||
nextTest(); | ||
done(); | ||
break; | ||
setTimeout( onComplete, DURATION_ANI ); | ||
case 3: | ||
t.equal( this.name, 'section 2', 'section 2 aniIn' ); | ||
done(); | ||
nextTest(); | ||
break; | ||
case 4: | ||
t.equal( this.name, 'section 3', 'section 3 aniIn' ); | ||
done(); | ||
nextTest(); | ||
break; | ||
case 6: | ||
t.equal( this.name, 'section 5', 'section 5 init' ); | ||
done(); | ||
break; | ||
} | ||
}, | ||
aniOut: function( onComplete ) { | ||
aniOut: function( req, done ) { | ||
switch( idxText ) { | ||
console.log( ( Date.now() - this.startTime ), 'aniOut', this.name ); | ||
case 3: | ||
t.equal( this.name, 'section 1', 'section 1 aniOut' ); | ||
done(); | ||
break; | ||
setTimeout( onComplete, DURATION_ANI ); | ||
case 4: | ||
t.equal( this.name, 'section 2', 'section 2 aniOut' ); | ||
done(); | ||
break; | ||
case 5: | ||
t.equal( this.name, 'section 3', 'section 3 aniOut' ); | ||
done(); | ||
break; | ||
} | ||
}, | ||
destroy: function() { | ||
destroy: function( req, done ) { | ||
switch( idxText ) { | ||
console.log( ( Date.now() - this.startTime ), 'destroyed', this.name ); | ||
case 3: | ||
t.equal( this.name, 'section 1', 'section 1 destroy' ); | ||
done(); | ||
break; | ||
case 4: | ||
t.equal( this.name, 'section 2', 'section 2 destroy' ); | ||
done(); | ||
break; | ||
case 5: | ||
t.equal( this.name, 'section 3', 'section 3 destroy' ); | ||
done(); | ||
nextTest(); | ||
break; | ||
case 6: | ||
t.equal( this.name, 'section 4', 'section 4 destroy' ); | ||
done(); | ||
break; | ||
} | ||
} | ||
}; | ||
doNormal(); | ||
function nextTest() { | ||
function doNormal( onComplete ) { | ||
idxText++; | ||
var v = vm(), | ||
c1 = Object.create( Content ), | ||
c2 = Object.create( Content ); | ||
switch( idxText ) { | ||
case 1: | ||
c1.name = 'c1'; | ||
c2.name = 'c2'; | ||
c1.startTime = c2.startTime = Date.now(); | ||
test( 'section init, aniIn, resize', function( nT ) { | ||
console.log( '---NORMAL---' ); | ||
v.show( c1, function() { | ||
t = nT; | ||
t.plan( 6 ); | ||
v.show( c2, function() { | ||
manager.show( new section( 'section 1' ), passedData, function() { | ||
console.log( '--------------\n' ); | ||
doWithoutOverlap(); | ||
}); | ||
}); | ||
} | ||
t.pass( 'called onComplete' ); | ||
}); | ||
}); | ||
break; | ||
function doWithoutOverlap() { | ||
case 2: | ||
test( 'resize section that is in', function( nT ) { | ||
var v = vm( { | ||
overlap: false | ||
}), | ||
c1 = Object.create( Content ), | ||
c2 = Object.create( Content ); | ||
t = nT; | ||
t.plan( 2 ); | ||
c1.name = 'c1'; | ||
c2.name = 'c2'; | ||
c1.startTime = c2.startTime = Date.now(); | ||
manager.resize( 333, 33 ); | ||
}); | ||
break; | ||
case 3: | ||
test( 'bring in section 2', function( nT ) { | ||
console.log( '---NO OVERLAP---' ); | ||
v.show( c1, 'some model', function() { | ||
t = nT; | ||
t.plan( 4 ); | ||
v.show( c2, 'some other model', function() { | ||
manager.show( new section( 'section 2' ) ); | ||
}); | ||
break; | ||
console.log( '------------\n' ); | ||
doWithOnlyInitAndDestroy(); | ||
}); | ||
}); | ||
} | ||
case 4: | ||
function doWithOnlyInitAndDestroy() { | ||
test( 'bring in section 3 without init', function( nT ) { | ||
var v = vm(), | ||
c1 = Object.create( Content ), | ||
c2 = Object.create( Content ); | ||
t = nT; | ||
t.plan( 3 ); | ||
c1.name = 'c1'; | ||
c2.name = 'c2'; | ||
c1.startTime = c2.startTime = Date.now(); | ||
c1.aniIn = c2.aniIn = undefined; | ||
c1.aniOut = c2.aniOut = undefined; | ||
var nSection = new section( 'section 3' ); | ||
console.log( '---NO ANI---' ); | ||
v.show( c1, function() { | ||
nSection.init = undefined; | ||
v.show( c2, function() { | ||
manager.show( nSection ); | ||
}); | ||
break; | ||
console.log( '------------\n' ); | ||
}); | ||
}); | ||
} | ||
case 5: | ||
test( 'bring in section 4 without init, aniIn', function( nT ) { | ||
t = nT; | ||
t.plan( 2 ); | ||
var nSection = new section( 'section 4' ); | ||
nSection.init = undefined; | ||
nSection.aniIn = undefined; | ||
nSection.aniOut = undefined; | ||
manager.show( nSection ); | ||
}); | ||
break; | ||
case 6: | ||
test( 'bring in section 5 test skipping aniOut on section 4', function( nT ) { | ||
t = nT; | ||
t.plan( 3 ); | ||
section5 = new section( 'section 5' ); | ||
manager.show( section5 ); | ||
}); | ||
break; | ||
case 7: | ||
test( 'bring in section 5 again', function( nT ) { | ||
t = nT; | ||
t.plan( 1 ); | ||
manager.show( section5 ); | ||
setTimeout( function() { | ||
t.pass( 'Didn\'t duplicate section 5' ); | ||
}, 33 ); | ||
}); | ||
break; | ||
} | ||
} | ||
nextTest(); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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 tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
12027
297
0
87
1
1