Socket
Socket
Sign inDemoInstall

ampersand-view-switcher

Package Overview
Dependencies
9
Maintainers
5
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

.zuul.yml

15

ampersand-view-switcher.js

@@ -9,2 +9,3 @@ /*$AMPERSAND_VERSION*/

empty: null,
prepend: false,
waitForRemove: false

@@ -35,4 +36,8 @@ };

if (this.config.waitForRemove) {
this.next = view;
this._hide(prev, function () {
self._show(view);
if (self.next === view) {
delete self.next;
self._show(view);
}
});

@@ -87,3 +92,9 @@ } else {

if (!view.rendered) view.render({containerEl: this.el});
if (!view.insertSelf) this.el.appendChild(view.el);
if (!view.insertSelf) {
if (this.config.prepend) {
this.el.insertBefore(view.el, this.el.firstChild);
} else {
this.el.appendChild(view.el);
}
}
};

@@ -90,0 +101,0 @@

25

package.json
{
"name": "ampersand-view-switcher",
"description": "A utility for swapping out views inside a container element.",
"version": "2.0.0",
"version": "2.1.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -20,8 +20,7 @@ "browserify": {

"browserify": "^6.2.0",
"jshint": "^2.9.1",
"phantomjs": "^1.9.12",
"precommit-hook": "^1.0.7",
"run-browser": "",
"tap-spec": "^1.0.1",
"tape": "^2.0.0",
"tape-run": "^0.3.0"
"precommit-hook": "^3.0.0",
"tape": "^4.4.0",
"zuul": "^3.9.0"
},

@@ -42,5 +41,13 @@ "homepage": "https://github.com/ampersandjs/ampersand-view-switcher",

"scripts": {
"start": "run-browser test/*",
"test": "browserify test/* | tape-run | tap-spec"
}
"start": "zuul --local -- test/main.js",
"test": "zuul --phantom -- test/main.js",
"test-ci": "zuul -- test/main.js",
"lint": "jshint .",
"validate": "npm ls"
},
"pre-commit": [
"lint",
"validate",
"test"
]
}
# ampersand-view-switcher
Lead Maintainer: [Kamil Ogórek](https://github.com/kamilogorek)
##Purpose
This module does one thing: *it helps you swap out views inside of an element*. It's compatible with ampersand-view, backbone views and any view that has an `.el`, `.render()` and `.remove()`

@@ -62,3 +66,3 @@

});
}
}
});

@@ -77,3 +81,3 @@ ```

hide: function (oldView, cb) {
// it's inserted and rendered for me so we'll add a class
// it's inserted and rendered for me so we'll add a class
// that has a corresponding CSS transition.

@@ -109,2 +113,3 @@ oldView.el.classList.add('animateOut');

* `waitForRemove` {Boolean} [default: `false`] Whether or not to wait until your `hide` animation callback gets called before starting your `show` animation.
* `prepend` {Boolean} [default: `false`] Whether or not to prepend the view to the `element`. When this is `false`, the view is appended.
* `empty` {Function} [optional] A function that gets called any time the view switcher is empty. Including when you instantiate it without giving it a view to start with.

@@ -111,0 +116,0 @@ * `view` {View} [optional] A view instance to start with.

@@ -69,6 +69,30 @@ var test = require('tape');

test('`options.hide', function(t) {
t.plan(3);
test('`options.show`', function (t) {
var TestView = makeTestView({
hide: function(oldView) {
show: function (newView) {
t.equal(newView, c1, 'first param should be new view');
}
});
var base = new TestView();
var c1 = new ItemView();
base.switcher.set(c1);
t.equal(base.el.firstChild, c1.el, 'the current view was set');
t.end();
});
test('`options.prepend`', function (t) {
var TestView = makeTestView({
prepend: true
});
var base = new TestView();
var c1 = new ItemView();
base.el.appendChild(document.createElement('div'));
base.switcher.set(c1);
t.equal(c1.el.parentNode.firstChild, c1.el, 'view was prepended to container');
t.end();
});
test('`options.hide`', function (t) {
var TestView = makeTestView({
hide: function (oldView) {
t.equal(oldView, c1, 'first param should be previous view');

@@ -84,9 +108,9 @@ }

t.equal(base.el.firstChild, c2.el, 'the current view was set');
t.end();
});
test('`option.hide` with `waitForRemove`', function(t) {
t.plan(4);
test('`option.hide` with `waitForRemove`', function (t) {
var TestView = makeTestView({
waitForRemove: true,
hide: function(oldView, cb) {
hide: function (oldView, cb) {
t.equal(oldView, c1, 'first param should be previous view');

@@ -104,2 +128,27 @@ t.ok(typeof cb === 'function', 'second param is callback');

t.equal(base.el.firstChild, c2.el, 'the current view was set');
t.end();
});
test('`option.show` and `option.hide` used together', function (t) {
var showCount = 0;
var hideCount = 0;
var TestView = makeTestView({
show: function () {
showCount++;
},
hide: function () {
hideCount++;
}
});
var base = new TestView();
var c1 = new ItemView();
var c2 = new ItemView();
base.switcher.set(c1);
t.equal(base.el.firstChild, c1.el, 'first view was set');
base.switcher.set(c2);
t.equal(c1.el.parentNode, null, 'first view was removed');
t.equal(base.el.firstChild, c2.el, 'second view was set');
t.equal(showCount, 2, 'show should be called for every view we set');
t.equal(hideCount, 1, 'hide should be called only once, after first view has been set');
t.end();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc