Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

templejs

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

templejs - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

24

lib/binding.js

@@ -294,5 +294,2 @@ var Events = require("./events"),

// init the function event methods
this._initEventMethods();
// the first event in the cycle, before everything else

@@ -372,22 +369,9 @@ this._mounting = true;

stop: function() {
if (this.isMounted()) this._comp.stop();
onInvalidate: function(fn) {
if (this.isMounted()) this._comp.onInvalidate(fn);
return this;
},
// turns a few events into instance methods to make this class more functional
// but also to match closer to FB's React component API
_initEventMethods: function() {
if (this._eventMethods) return this;
this._eventMethods = true;
["mount","render","invalidate"].forEach(function(evt) {
var caps = evt[0].toUpperCase() + evt.substr(1);
this.on(evt + ":before", util.runIfExists(this, "before" + caps));
this.on(evt, util.runIfExists(this, "on" + caps));
this.on(evt + ":after", util.runIfExists(this, "after" + caps));
}, this);
this.on("stop", util.runIfExists(this, "onStop"));
stop: function() {
if (this.isMounted()) this._comp.stop();
return this;

@@ -394,0 +378,0 @@ }

4

lib/index.js

@@ -17,3 +17,3 @@ var Binding = require("./binding"),

// static properties/methods
Temple.VERSION = "0.4.0";
Temple.VERSION = "0.4.1";
Temple.util = util;

@@ -24,3 +24,3 @@ Temple.Events = require("./events");

// deps setup
var Deps = Temple.Deps = require("trackr");
var Deps = Temple.Trackr = Temple.Deps = require("trackr");
Temple.autorun = Deps.autorun;

@@ -27,0 +27,0 @@ Temple.nonreactive = Deps.nonreactive;

@@ -38,6 +38,6 @@ var Binding = require("./binding"),

addEventListener: function(type, sel, listener, options) {
addEventListener: function(type, sel, listener, ctx) {
var self = this;
// syntax: addEventListener({ "type selector": listener }, options)
// syntax: addEventListener({ "type selector": listener }, ctx)
if (util.isObject(type)) {

@@ -52,5 +52,5 @@ util.each(type, function(v, n) {

// syntax: addEventListener(type, listener, options)
// syntax: addEventListener(type, listener, ctx)
if (typeof sel === "function") {
if (options == null) options = listener;
if (ctx == null) ctx = listener;
listener = sel;

@@ -60,4 +60,2 @@ sel = null;

options = options || {};
if (typeof type !== "string" || type === "") {

@@ -72,3 +70,3 @@ throw new Error("Expecting non-empty string event name.");

if (this._eventListeners == null) this._eventListeners = [];
this._eventListeners.push({ type: type, listener: listener, event: eventListener, options: options });
this._eventListeners.push({ type: type, listener: listener, event: eventListener });
this.node.addEventListener(type, eventListener);

@@ -86,19 +84,32 @@

if (options.once) self.removeEventListener(type, listener);
listener.call(options.context || self, e, delegate);
listener.call(ctx || self, e, delegate);
}
},
addEventListenerOnce: function(type, sel, listener, options) {
addEventListenerOnce: function(type, sel, listener, ctx) {
// syntax: addEventListenerOnce({ "type selector": listener }, ctx)
if (util.isObject(type)) {
return this.addEventListener(type, util.extend({ once: true }, sel || {}));
return this.addEventListenerOnce(type, sel);
}
// syntax: addEventListenerOnce(type, listener, ctx)
if (typeof sel === "function") {
if (options == null) options = listener;
if (ctx == null) ctx = listener;
listener = sel;
sel = null;
}
var self = this;
var ran = false;
function fn() {
if (ran) return;
ran = true;
self.off(name, fn);
listener.apply(this, arguments);
}
fn._listener = listener;
return this.addEventListener(type, sel, listener, util.extend({ once: true }, options || {}));
return this.addEventListener(type, sel, fn, ctx);
},

@@ -111,2 +122,3 @@

// syntax: removeEventListener(listener)
if (typeof type === "function" && listener == null) {

@@ -117,2 +129,3 @@ listener = type;

// syntax: removeEventListener({ "type selector": listener })
if (util.isObject(type)) {

@@ -122,8 +135,16 @@ util.each(type, function(v, n) {

evts.push.apply(evts, this._eventListeners.filter(function(e) {
return e.type === m[1] && e.listener === v && !~evts.indexOf(e);
return e.type === m[1] && (e.listener === v || e.listener._listener === v) && !~evts.indexOf(e);
}));
}, this);
} else {
}
// syntax: removeEventListener(type)
else if (listener == null) {
evts = _.clone(this._eventListeners);
}
// syntax: removeEventListener(type, selector)
else {
evts = this._eventListeners.filter(function(e) {
return (type == null || type === e.type) && (listener == null || listener === e.listener);
return (type == null || type === e.type) && (listener === e.listener || listener === e.listener._listener);
});

@@ -370,17 +391,2 @@ }

return nodes.length === 1 ? nodes[0] : new Binding().append(nodes);
}
// converts a simple css selector to an element binding
exports.fromSelector = function(sel) {
if (typeof sel !== "object") {
sel = util.parseSelector(sel);
}
var el = new Element(sel.tagname);
if (sel.id != null) el.prop("id", sel.id);
el.addClass(sel.classes);
el.attr(sel.attributes);
el.append(util.toArray(arguments).slice(1));
return el;
}

@@ -141,3 +141,3 @@ var toArray =

if (node.nodeType === window.Node.ELEMENT_NODE) {
return app.View.util.matchesSelector(node, selector);
return matchesSelector.call(node, selector);
}

@@ -177,10 +177,2 @@

exports.runIfExists = function(obj, method) {
return function() {
if (typeof obj[method] === "function") {
return obj[method].apply(obj, arguments);
}
}
}
var Trackr = require("trackr");

@@ -201,7 +193,5 @@

// runs the coercion function non-reactively to prevent infinite loops
function process(v) {
return Trackr.nonreactive(function() {
return coerce.call(obj, v, prop, obj);
});
}
var process = Trackr.nonreactable(function(v) {
return coerce.call(obj, v, prop, obj);
});

@@ -208,0 +198,0 @@ var dep = new Trackr.Dependency;

{
"name": "templejs",
"version": "0.4.0",
"version": "0.4.1",
"description": "A modern JavaScript view framework.",

@@ -26,3 +26,3 @@ "author": "Beneath the Ink <info@beneaththeink.com>",

"dependencies": {
"trackr": "~1.0.0"
"trackr": "~1.0.1"
},

@@ -33,8 +33,4 @@ "devDependencies": {

"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-copy": "~0.7.0",
"grunt-contrib-uglify": "~0.7.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-copy": "~0.1.0",
"grunt-peg": "~1.5.0",
"grunt-wait": "~0.1.0",
"grunt-wrap2000": "~0.1.0",

@@ -41,0 +37,0 @@ "chai": "~2.0.0",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc