Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Symphony.General (general functions in JS) #1038

Closed
ghost opened this Issue Mar 1, 2012 · 14 comments

Comments

Projects
None yet
5 participants
@ghost

ghost commented Mar 1, 2012

Exposing some general functions (like "General::createHandle") to JS.

Owner

brendo commented Mar 1, 2012

At this stage it's out of scope for the initial 2.3 release (not because it's difficult, but just because a line has to be drawn somewhere ;)).

The main way I see this working is using AJAX to hit up a dedicated page the exposes some of the General functions (where appropriate) for use in Javascript. Essentially it would work very similar to translations.

Possible exposure targets:

  • createHandle
  • createFilename
  • hash
  • formatFilesize
  • sanitize
  • reverse_sanitize
  • countWords
  • limitWords
  • validateURL
Owner

designermonkey commented Mar 1, 2012

I was just thinking that, about AJAX.

I don't mind doing this one, once we've got 2.3 out of the door, and the new JS model is laid down.

Contributor

nickdunn commented Mar 1, 2012

Yeah createHandle would be super useful. Would a blocking AJAX request be performant? If not, it should be relatively simple to port most of the regex from the createHandle method to JS.

Owner

nilshoerrmann commented Mar 1, 2012

We discussed that in another thread here (I don't remember which though) and we concluded that – thinking about maintenance – it wouldn't be the best idea to replicate the needed code in JavaScript. So the idea was to use AJAX

Would a blocking AJAX request be performant?

The question is in which situations these functions are really needed (I cannot think of that many) and if in these cases a synchronous call is needed.

@ghost

ghost commented Mar 2, 2012

If not, it should be relatively simple to port most of the regex from the createHandle method to JS.

I would prefer actually porting needed functions to JS instead of just making them available via Ajax. The latter would be a somewhat hacky approach, I don't think this is a route Symphony should take.

Owner

brendo commented Mar 2, 2012

Can you elaborate more about why you feel it's the wrong approach?

Having code in two different locations that does the same thing seems wrong to me. There are some functions in PHP that would cumbersome to replicate in Javascript (and probably vice versa) or might not be able to replicate the functionality which would mean slightly different results which could cause issues.

All Javascript translation is currently implemented with AJAX in a similar fashion to utilise the Lang class, so I don't see a reason why we shouldn't follow in it's footsteps.

@ghost

ghost commented Mar 2, 2012

Can you elaborate more about why you feel it's the wrong approach?

Not really, sorry. Accessing PHP functions from JavaScript just feels wrong to me and I would have never thought of it to begin with, but maybe you're right, at least from a more practical point of view.

I tend to forget with whom I'm discussing here and that you guys already thought stuff through pretty well, at least most of the time.

Owner

brendo commented Mar 2, 2012

Heh, that's fine, I understand, it's just one of those 'in my gut it doesn't sit right' feelings :)

@ghost

ghost commented Mar 2, 2012

Exactly ;)

Owner

nilshoerrmann commented Mar 2, 2012

Thr most important question is: why should we offer these functions in JavaScript? Are we convinced that they are needed?

Contributor

nickdunn commented Mar 2, 2012

Why should we offer these functions in JavaScript? Are we convinced that they are needed?

Extensions. Several times I have recreated a createHandle function for my own use. But other than that I haven't needed the others. Brendo's list looks fine, but we shouldn't just expose them because we can. For sure.

Owner

brendo commented Mar 2, 2012

createHandle is probably the essential function.

I can see all of them being useful at some point (Drag & Drop file uploads), but it's a little chicken and egg I guess.

benesch commented Mar 3, 2012

I just happened across this issue, but I figured I'd throw in my two cents. I'm with Jens: I'd hate to see Symphony making network requests for what's essentially a couple regular expressions. At the least, you'd need to allow batch requests if someone needed to generate 100 handles on the fly. (Not that I can think of a use case.)

I can see the elegance in exposing the entire interface via AJAX, but if createHandle is the main draw, I think it's worth it to just port the function to Javascript. Ideally, you could store the transliterations as JSON so they'd be accessible to the JS.

Owner

brendo commented Mar 8, 2012

Bah. Been going around in circles when this functionality already exists for handles!

/symphony/ajax/handle/?string=Your String will return a handled version.

I think it's safe this is considered the most important function so far, so I'll close this issue.

@brendo brendo closed this Mar 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment