Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Idea for new feature in Alloy : once and debounce events

$
0
0

I have an idea that I would like to ask in Jira but first I'd like to know your opinion about it. I need to define some events that must be triggered only once, and some other that I need to be debounced.

index.xml

<Alloy>
    <Window onPostlayout="postlayout">
        <Button onClick="click" title="click me" />
    </Window>
</Alloy>
index.js
function postlayout() {
    $.index.removeEventListener('postlayout', postlayout);
    Ti.API.info('Post layout run once!');
};
 
function click() {
    debouncedClick();
};
 
var clickOnced = _.debounce(function () {
    Ti.API.info('Debounced click');
}, 700, true);
I always have to write this kind of code which is quite not cool. I tried to use this king of code (see below) which was quite cool but it doesn't work because of this https://jira.appcelerator.org/browse/ALOY-969

index.js

var postlayout = _.once(function () {
    Ti.API.info('Post layout run once!');
});
 
var click = _.debounce(function () {
    Ti.API.info('Debouncde click');
}, 700, true);
Here is a solution I would like to have in Alloy, based only on Alloy

index.xml

<Alloy>
    <Window oncePostlayout="postlayout">
        <Button ondebounceClick="click" title="click me" />
    </Window>
</Alloy>
What I was thinking is to make my own module, but I know I'll be tired to write ns="my.own.eventModule" every where, and what about fields that needs more than one namespaces?

Then I ask you it here : is it a good idea? Of course, the decision about syntax should be discussed and taken. We could have this &lt;Window onPostlayout:once=&quot;postlayout&quot;&gt;&lt;Button onClick:debounce=&quot;click&quot; /&gt;&lt;ScrollView onScroll:throttle=&quot;scroll&quot; /&gt;&lt;/Window&gt; (this is not nice xml) or other idea?

The parameters of debounce, throttle, etc. have a default value defined by the Alloy, but could be overloaded by the config.json, or in the parameter value like &lt;Button onClick=&quot;click,debounce,700&quot; /&gt; ...

Than you for your returns


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>