TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Large-scale JavaScript: A monolithic service layer

6 pointsby mrjoelkempover 11 years ago

3 comments

tlackover 11 years ago
If I was dealing with 40+ diverse services that I needed anywhere within various JavaScript apps, I&#x27;d probably write some kind of mediating service broker:<p><pre><code> var App = new YouNow(); var Bcast = App.Api(&#x27;BroadcastService&#x27;); Bcast.Api.send(msg).then(cb); </code></pre> Your code doesn&#x27;t have to care about where the services come from, it just has to comply with the services&#x27; APIs.<p>Thinking about your code structure as backend-provided services gives you the flexibility to do a Require.JS-style async dependency loading approach if needed. Imagine the following defined in api&#x2F;services&#x2F;BroadcastService&#x2F;index.js:<p><pre><code> service.define(&#x27;BroadcastService&#x27;, [&#x27;MessagingService&#x27;, &#x27;VideoTranscodingService&#x27;], function(MS, VTS) { &#x2F;&#x2F; do stuff with services, &#x2F;&#x2F; return a promise } ); </code></pre> A style like this allows you to mix and match a bunch of different interesting architectural approaches, with relative ease, and the safety of decoupled software components.<p>As usual your sticking points with this kind of hierarchical component system will be caching and out-of-band (component-to-component) messaging and state changes. For instance: what happens to the notion of a global &#x27;Session&#x27; object?
aboodmanover 11 years ago
<i>edit:</i> removed snark.<p>You should not be worrying about object size. Write libraries in a way that makes sense for your problem, then use Closure compiler to strip the unused code from each application.
评论 #6907161 未加载
thenerdfilesover 11 years ago
I&#x27;ve been exploring both Alt. 2 and Alt. 3. 2 with AngularJS and 3 with Backbone+Marionette. Evental communication within Models, which are entities, to views and controllers is easy and fun. A model is essentially a service anyway, so methods are more intuitive to name.
评论 #6906889 未加载