developmentseed / developmentseed/bones

Location for client-space singletons

Open
#4 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
481
Forks
39
PR merge metrics
No merged PRs in 30d

Description

Right now we hang client-space singletons like `admin` or `user` off of the `Bones` object - only client-side. Typically, a code like the snippet below is executed client-side to set up a global object, modules like `bones-document` would then rely on it.

```
$(function() {
Bones.start();
Bones.initialize(function(models, views, controllers, templates) {
Bones.user = new models['User']();
Bones.user.status();
// ...
```
## Two problems:

1) This pattern cannot be replicated on the server as such global objects would be in the global application scope, not in the client (= window) scope.
2) Having a global object X set up to make a module work as expected is not ideal, we should review better patterns (passing a user/admin/whatever object into constructors?)

Right now we're making hesitant use of the existing pattern described initially. If we solve this issue, we could make much safer assumptions around client space singletons and push more code into modules like `bones-auth` and `bones-document` = reuse more code.
## Potential solutions

Bones could provide a 'request' object that would hang off an Express request server side and the `window` object client side. This 'request' object (better name?) would provide a safe space for client space objects.

More thoughts needed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.