The MarkLogic JavaScript API, MLJS, has been a huge help in my developing apps quickly for prospects, partners and customers on MarkLogic. In this post I detail some of my fave things about MLJS that you may not realise!
Starting from the average to the awesome!…
10. MLJS can be used with Angular.js
MLJS’ core connection object can be wrapped easily with an Angular service. I’ve also experimented with adding promises in to Context objects (see point 6!). Search Context fully supports promises, making it easily compatible with Angular.
9. MLJS uses Bootstrap and 960.css
If you’re app uses 960.css for layout, MLJS will use those classes natively. Demo apps in MLJS are developed assuming a 12 column layout. Also, MLJS uses some of the bootstrap css classes. In May 2014 I’ll re-work ALL widgets to use Bootstrap more extensively.
You don’t have to use either framework though – every single element in MLJS browser widgets has it’s own class name, making it trivial to style using your own CSS
8. MLJS is ui framework agnostic
You can write widgets in jQuery, or DoJo, or use an Angular.js page controller – MLJS doesn’t care! I’ve added no hard dependencies to MLJS. Only exceptions are low level logging (using Winston on Node.js), and jQuery when using the Highcharts or explorer widgets – it’s a HighCharts dependency.
7. MLJS works in Node.js and in the browser
MLJS’ core connection API wraps the MarkLogic REST endpoints. Context objects (see 6) and the Core connection can both be used in Node.js or in the browser without any code changes. Browser widgets are provided that use context objects to display information and allow user’s to interact with a MarkLogic application.
6. MLJS provides mid level state co-ordination objects – contexts
There are search context, semantic context, document context and alert context objects. They handle a single piece of state that may be updated by multiple objects. A great example is a search interface with search bar, pagination, sorting, facet, metrics and results widgets. Interacting with these all affects a small piece of the search object.
This search query and options are managed by the search context object. This minimises what each widget needs to know about the overall search configuration. The semantic context allows lookup and caching of Subject information, and the tripleconfig object allows you to create an ontology in just a few lines of JavaScript.
5. MLJS is an open source project with multiple contributors
MLJS is entirely Apache 2 licensed, and will always be so! Many people in and out of MarkLogic have sent me pull requests and feature requests over the last 18 months. I even have MarkLogic consultants contributing code at the moment for Grunt, Yeoman and Bower integration! Park of their quarterly MBOs (bonus targets) are contributing to MLJS! Partners are very good at submitting bug reports and pull requests too. Thanks to all you who have contributed!
4. MLJS makes me smile
Whenever I talk to customers or internally they tend to say “It’d be cool if…” – then I wheel out an MLJS widget screen shot that gets the creative juices flowing. Before you know it you have an idea for an app or demo, and a way to create it quick!
3. MLJS has very rich browser widgets
There are over 39 widgets, with more in development. 19 of these are ‘end user’ ready, like search page elements, co-occurence, tag cloud, or high charts widgets. I even have a Workplace Widget in development that allows in browser drag/drop page editing – a portal in the browser for all MLJS widgets!
2. MLJS saves me tonnes of time
I hate writing the same piece of code twice. That’s why MLJS exists – because I’m lazy! I write new functionality, commit it to the MLJS repo on GitHub, and it continues to grow! Over 30000 lines of code in MLJS now in just 18 months! I recently wrote an app in 2 days that 18 months ago would have taken 2-3 weeks! Now I only have to add limited new functionality to widgets, rather than start from scratch. I can’t even remember the last time I wrote XQuery in anger!!!
1. MLJS is being used all over!
MLJS is being used internally in MarkLogic, by partners and customers! 2-tier apps are being built for demos, PoCs and very soon production apps! I personally know of 16 projects that have used MLJS – with only half of them being my own projects!
Further Info
Check MLJS for yourself here: https://github.com/adamfowleruk/mljs/wiki