signalpoint / jDrupal

A JavaScript Library and API for Drupal Applications
http://jdrupal.tylerfrankenstein.com/
GNU General Public License v2.0
76 stars 38 forks source link

How to properly use the pre/post process callbacks? #71

Open hanoii opened 7 years ago

hanoii commented 7 years ago

Do I need to add something manually to jDrupal.modules for it to be picked up and then just define a function in the global scope?

so would it be:

  1. jDrupal.modules['something'] and then

2.function something_rest_pre_process(xhr, data) {} on the global spec?

Is 1 necessary?

signalpoint commented 7 years ago

@hanoii Yes, step no. 1 is necessary. Perhaps we should add something like jDrupal.addModule(); (and some corresponding docs) to make this more intuitive. Not many people get into jDrupal custom modules, 99% of the time people are using jDrupal by way of DrupalGap, and the usage of modules that way is much more well documented. Then we could have something like:

jDrupal.addModule('something');
function something_rest_pre_process(xhr, data) {
  // Do something...
}

Your thoughts?

hanoii commented 7 years ago

that's fine although it was mainly lack of documentation.

As for further thoughts/preference I would have preferred something that doesn't require me to add it to the global spec.

Maybe using javascript events.

Or, if you want to still add it to jDrupal, maybe do it in a way similar to Drupal.behaviors where what you add there has the methods self-contained.

But this could possible mean quite a in the logic for you I guess and as you say is for little uses.