Can I import code into the VIEW CODE Javascript?


#1

I need to write an extensive, yet logically simple (a bunch of if statements) code for my MAP function.

As I will need to rewrite a lot of code between different views I would like to know if I can import code into them.

I know that this is probably impossible with the current implementation of Couchbase, but I’m seriously considering building my own custom version, even if it implies messing a lot with the source code from it or even from V8.

Other thing that bothers me is the size limit for the document where the view code is stored, there’s a way to disable this?

Thanks!


#2

I have done this just by bringing the externally defined functions (other than the one handling the document) in as part of the view. It works well, as long as you’re comfortable managing it a bit externally. I have one example in changedetector.

If you want to put them in a common area, there isn’t a standard way to do this that I know of. The source repo to look through for archeological clues is the this repository. You may find a simple include directory defined there somewhere. Or @vmx may be able to point you to somehting I’m not aware of.

I’m not familiar with the size limit-- how big is the view you’re trying to post?


#3

I’m not aware of any size limits in regards to design documents. If you hit any, please give more details.

You currently can’t import code.

As coding views directly in the UI isn’t pleasant, I’d expect that you code them with some editor. As you say they’re quite complex I’d probably put them under version control. Easiest is then to add a build step which just concatenates the files you depend on, so that you end up with a single file per view.


#4

Thanks, guys!

The UI seems to act weird with anything bigger than a few kBs, but I’ve manage to use a document as big as 2MB through the REST API with no issues.


#5

Good to hear.

I forgot to add that there’s an open issue MB-15437 about having module support. You might want to watch it (you can log into Jira with the same credentials as for this forum).