Skip to content

Instantly share code, notes, and snippets.

@kovchiy
Created April 16, 2017 13:48
Show Gist options
  • Save kovchiy/fba8b52ded2185c7a06b8962ab68f313 to your computer and use it in GitHub Desktop.
Save kovchiy/fba8b52ded2185c7a06b8962ab68f313 to your computer and use it in GitHub Desktop.
Beast.decl({
Counter: {
abstract:true,
countOn: {
// event: token
},
param: {
counterData: {
/* NDA */
}
},
domInit: function () {
for (var eventName in this.countOn) {
this.on(eventName, function (token) {
this.count(
typeof token === 'function' ? token.call(this) : token
)
}.bind(this, this.countOn[eventName]))
}
},
count: function (token) {
this.param('counterData').path = token
this.param('counterData').ts = (new Date).getTime()
var counterString = ''
for (var key in this.param('counterData')) {
counterString += '/' + key + '=' + this.param('counterData')[key]
}
Native.httpRequest({
url: 'http://NDA/' + counterString + '/*',
cancelPrevious: false,
})
}
}
})
// Теперь любой компонент может цеплять к себе счетчик на событие:
Beast.decl({
NewsStory__proceed: { // Кнопка "Читать полностью" в новостном блоке
inherits: ['Counter', 'Control'],
countOn: {
Press: function () { // Кроссплатформенное событие нажатия от "Control"
return 'event.news.story.alternative.' + this.index()
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment