Closed arvgta closed 4 years ago
From my perspective seems that the first option would be better. For second variant we'll probably need giant for/foreach loop and names of getters/setters would be limited to one character possibly. But even that is not much of an issue because, as you said, we have whole alphabet doubled (case sensitive checks), and big spectrum of symbols. Letter case can be even used to determine the return of the call or some additional instructions. For example:
$.rq("v", ev); // will do just "v", but
$.rq("V", ev); // will do "vi".
To make it more clear, here is working example:
if(o.toUpperCase() === "V") { //validate value passed in "p", which is expected to be a click event value - also performs "i" afterwards
if(!p) return false; //ensure data
e = p; //store event internally
c = e.currentTarget; //extract currentTarget
h = c.href; //extract href
if(!_internal(h)) return false; //if not internal -> report failure
if (o === "V") o = "i"; //continue with "i"
}
What you think?
Thanks Edin! I reallly like your suggestion with the case sensitviity to distinguish between setters and getters, or different handlers on the same piece of data!
I've tweaked canonical URL handling accordingly...
Regarding your working example:
if(o.toLowerCase() === "v") //softer on the eye
Apart from that I don't want to throw out the idea of performing multiple steps at once just yet...
Don't think, that it will be much more complex than a String.indexOf()
, only that it might have to handle case additionally.
Yes, I would opt for each step to be indicated by a single character, but the standard method for "jumping" into the desired steps could be handled by the pO()
function itself...
Any combination of steps could be specified by the user.
After all, what you proposed is a cooperative method between the client and $.rq
anyway, so we might take this cooperation one step further...
I have only performed the following changes to $.rq
:
if(o === "v") { //validate value passed in "p", which is expected to be a click event value - also performs "i" afterwards
if(!p) return false; //ensure data
e = p; //store event internally
h = typeof e !== "string" ? e.currentTarget.href || e.originalEvent.state.url : e; //extract href
if(!_internal(h)) return false; //if not internal -> report failure
o = "i"; //continue with "i"
}
if(o === "i") { //initialise request defaults and return "c" (currentTarget)
ispost = false; //GET assumed
data = null; //reset data
push = true; //assume we want to push URL to the History API
can = false; //reset can (canonical URL)
return h; //return "h" (href)
}
These two lines have been changed:
h = typeof e !== "string" ? e.currentTarget.href || e.originalEvent.state.url : e; //extract href
return h; //return "h" (href)
The calling functions (clients) have been simpified accordingly... For example, it is now possible to do the following in one single step:
var h = $.rq("v", ev); //validate event and return the href
Purpose:
rq
stands for "request"This sub-plugin is at the heart of Ajaxify. The idea is to collect data pertaining to the request centrally and flexibily rather than passing it around. It already has succeeded in relieving the client code on many occasions. Furthermore, the data can be persistent, potentially even across page loads.
I would like to enrich
rq
, simplify calls for clients and ideally downsize, concerning the following code:From here on:
href
... will be referred to as "steps"...
Problems: things I don't like about the current code:
rq
are made sequentially, they cannot be performed in one go.c
(currentTarget), which is fetched twice at the moment but never needed in practice (client calls always want thehref
and extract it "by foot" instead, which is not elegant at all).href
, even if it could be done in one pass.There are principally two very different solutions:
$.rq
more self-managing, so that it renders the value with the maximum conveniency in all cases.In the second variant, all steps would be processed sequentially as follows:
p
p
href
(in one go..)Question:
1. Does the second variant go down well with object-oriented paradigms, or is it known to defeat its purpose?