Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client-side support? #74

Open
ghost opened this issue May 16, 2011 · 8 comments
Open

client-side support? #74

ghost opened this issue May 16, 2011 · 8 comments

Comments

@ghost
Copy link

ghost commented May 16, 2011

I use jquery.couch.js for accessing couch from a client browser. I also wrote a thin jquery that implemented just enough for jquery.couch.js to work in node. Now I can write code that works identically in either the server or the client. This has been in production for months.

However, jquery.couch.js is not wonderful. I would really like to use cradle, but I'm trying to use all tools that are transparent to whether they are in the client or server. How hard would it be to do a client version of cradle?

I would take anything but ideally it would work with jquery and ajax. Websockets is a little immature right now.

I haven't looked at cradle's code yet. Does all traffic flow through a single http-client routine? If so I would think hooking it up to jquery would be pretty easy. As I mentioned above I did the opposite and it only took me a day or so.

@indexzero
Copy link
Member

If I were going to do it ... I would probably estimate it at about 20 hours of work. I feel like I have a pretty solid understanding of the code base.

Try digging in, things to look out for:

  1. ECMA5-isms (Object.keys, etc)
  2. Variable namespace conflicts (see https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L308)
  3. require(...) usage
  4. Basically everything inside of rawRequest(): https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L93

I honestly don't view this as a high priority for cradle. Maybe the best thing to do here is to create a separate library "inspired by" cradle?

Just my $0.02

@ghost
Copy link
Author

ghost commented May 16, 2011

It may be too much work but I feel quite different about the need for
it. Half my couch access is from the client and I already have too
many languages, frameworks, and apis to remember. Any module that
also works client-side has a leg up.

On Mon, May 16, 2011 at 1:16 AM, indexzero
reply@reply.github.com
wrote:

If I were going to do it ... I would probably estimate it at about 20 hours of work. I feel like I have a pretty solid understanding of the code base.

Try digging in, things to look out for:

  1. ECMA5-isms (Object.keys, etc)
  2. Variable namespace conflicts (see https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L308)
  3. require(...) usage
  4. Basically everything inside of rawRequest(): https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L93

I honestly don't view this as a high priority for cradle. Maybe the best thing to do here is to create a separate library "inspired by" cradle?

Just my $0.02

Reply to this email directly or view it on GitHub:
#74 (comment)

Mark Hahn
Website Manager
mark@boutiquing.com
949-229-1012

@cloudhead
Copy link
Contributor

I think it's an interesting idea, and would be beneficial, but alas don't have the time for it. I don't think it would be too hard, as it pretty much has no dependencies, and most of the node-specific code is in request and rawRequest. There is also some node-specific code in changes and save/getAttachment. The rest of it should pretty much run as-is on the browser, minus what @indexzero said.

@ghost
Copy link
Author

ghost commented May 16, 2011

  1. ECMA5-isms (Object.keys, etc)

Could I replace these with function calls that conditionally use
jQuery? I ask because I wouldn't want to support a fork. The
powers-that-be (you?) would need to approve the techniques in advance.

  1. Variable namespace conflicts (see https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L308)

I glanced at that code, but I don't understand the problem. What
variables would clash?

  1. require(...) usage

There are packages that allow node modules to run in any browser.
They even load the dependencies.

  1. Basically everything inside of rawRequest(): https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L93

Yes. This is to be expected.

On Mon, May 16, 2011 at 1:16 AM, indexzero
reply@reply.github.com
wrote:

If I were going to do it ... I would probably estimate it at about 20 hours of work. I feel like I have a pretty solid understanding of the code base.

Try digging in, things to look out for:

  1. ECMA5-isms (Object.keys, etc)
  2. Variable namespace conflicts (see https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L308)
  3. require(...) usage
  4. Basically everything inside of rawRequest(): https://github.com/cloudhead/cradle/blob/master/lib/cradle.js#L93

I honestly don't view this as a high priority for cradle. Maybe the best thing to do here is to create a separate library "inspired by" cradle?

Just my $0.02

Reply to this email directly or view it on GitHub:
#74 (comment)

Mark Hahn
Website Manager
mark@boutiquing.com
949-229-1012

@indexzero
Copy link
Member

  1. I think this is a decision for @cloudhead. Personally, I wouldn't want to add any jQuery dependencies for simple iteration. You can usually do all of this slightly more verbosely with pure Javascript. The async library from @caolan (https://github.com/caolan/async) is a great example of how to do simple node and browser compatible code.
  2. My understanding is that the locally scoped document variable may conflict with window.document in certain scenarios. I may be wrong about this.
  3. If you're going to use something like that I would suggest either node-browserify (https://github.com/substack/node-browserify) or require (https://github.com/marcuswestin/require) from @marcuswestin. A good comparison of the two is here: nodejitsu/require-analyzer@7b7c96b#commitcomment-364835

Again, just my $0.02

@marcuswestin
Copy link

require would be a good fit. let me know if I can help.

@ghost
Copy link
Author

ghost commented May 17, 2011

require would be a good fit. let me know if I can help.

I am still trying to decide if I can spend the time on this, so any
help would be appreciated. My specialty is net stuff so I could work
on the http routine. Maybe you could help with require and/or
browserfy?

On Mon, May 16, 2011 at 6:11 PM, marcuswestin
reply@reply.github.com
wrote:

require would be a good fit. let me know if I can help.

Reply to this email directly or view it on GitHub:
#74 (comment)

Mark Hahn
Website Manager
mark@boutiquing.com
949-229-1012

@marcuswestin
Copy link

I'm tight on time myself, but this will get you started:

mkdir app
cd app
echo '{ "name":"app" }' > package.json
sudo npm install require
sudo npm install raphael
curl -O https://gist.github.com/raw/975866/8455988f04492512980fe25ced7d2dfcc5f8226e/little_server.js
curl -O https://gist.github.com/raw/975868/d547101ca15d3b52b9269948f6b4a805f6d9facc/little_client.js
node little_server.js

Then open http://localhost:8080 in browser

After that, try

sudo npm install cradle

and add require("cradle") in little_client.js. You can refresh without restarting the server. It'll probably complain about a sys module that it uses, like fs. That's where the work lies :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants