Add append and prepend functions/parameters
ValentinBrclz opened this issue · 6 comments
Hello macbre,
I'd like to use the prepend and append (section="new") edit, but don't know how is the best way to do it.
Maybe the edit function could be enhanced or other functions could be created....
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=edit
Best
The edit
function already has many arguments (function(title, content, summary, minor, callback)
). I'd rather create a new set of functions.
Hi @macbre , I do apreciate your work. As you said, "function already has many arguments", IMHO why not start switching to named parameters?
Don't take too serious! It's just opinion of a hobbyists Javascript programmer :)
Obs.: sorry for my poor english, I did not train it for long years!
@guiwp: no worries, thanks for feedback!
Named parameters? Can you elaborate on this one? ES6 introduced the default parameters value, but I don't think it has the same feature set as in Python for instance (where named parameters can be skipped and provided in any order).
We can of course switch to just a single parameter there that will be an object with an arbitrary list of fields that can be skipped. But this will brake the existing code that uses this function. Hence, I'm still for introducing the new function - the implementation will be less complex and the client code easier to read.
As for your English, practice makes perfect, even on GitHub :)
Hi @macbre , you said "But this will brake the existing code that uses this function"
What about auxiliary functions to keep compatibility? (don't known the correct terminology here)
getArticle(titles, callback){ //some code to check if the arguments are to call old version of getArticle //ex.: arguments.lenght > 1 //if(old){ _getArticles({ titles: titles, callback: callback }); }
Anyway, simplicity by design is a good idea. Keep up the good work!
My 2 cents would be to create an edit(opts, callback)
functions called by other functions like prepend(), append() and the current edit() one that could be renamed
Introducing the doEdit
helper that will internally handle calls to edit
, prepend
and append
makes perfect sense.