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

A Few Newb Questions #138

Closed
MehmetKursat opened this issue Dec 13, 2015 · 6 comments
Closed

A Few Newb Questions #138

MehmetKursat opened this issue Dec 13, 2015 · 6 comments

Comments

@MehmetKursat
Copy link

Hello,

Firstly thanks for this awesome project, I am not a very experienced developer but the simplicity of this and easily understandable explanations got me interested in this project and I like it.

However I have a couple of questions:

  1. Where is the best place to put initialization codes of other libraries? E.g. I am using NeDB for database management and I need to call this "mydatabase.loadDatabase();" function in somewhere so some services and modules can access to the database.
  2. I couldn't clearly understand the difference between Behaviors and Services even though I read it few times, could you give me an example or two that shows why it is best to use Services for that specific task and not Behaviors, and vice versa?

Thanks

@MehmetKursat MehmetKursat changed the title Few Newb Questions A Few Newb Questions Dec 13, 2015
@zephraph
Copy link
Contributor

Hey @FiatPax,

I can probably answer these. For number 1, I'd likely wrap the NeDB interface in a service. If you only need to do the initialization once per page then you could just put it in the startup stuff in the init method of the service.

Box.Application.addService('NeDB', function(app) {
  return {
    init: function() { /* intialize NeDB stuff here */ }
  }
});

If you think you'll have multiple modules that need to init the database drivers on the same page in different ways then I'd look at making your service perform like a factory. The services api documentation has a good reference on doing that. (Look under patterns/factory).

As for your second question, that's fairly easy.

Behaviors can do just about everything a module can do. Ultimately behaviors are how you share reusable functionality between modules. That means if you have a signup button that appears in a couple of your modules you can implement the functionality of what it does on click in a behavior and then share that between modules.

A service on the other hand is just a general, reusable utility. You'd use it to wrap your database driver, or to handle loading in asynchronous content.

I'd recommend you read through all three sections of the documentation. The getting started part gives you a bit of information but the guides and api sections are really where you get into the meat of it.

@MehmetKursat
Copy link
Author

Hello @zephraph , thank you! Your answer has cleared my problems fair enough.

@zephraph
Copy link
Contributor

No problem. Feel free to close the issue if you have no more questions. 😄

@MehmetKursat
Copy link
Author

@zephraph Sure :)

@nzakas
Copy link
Contributor

nzakas commented Dec 14, 2015

Thanks @zephraph , very well explained!

@zephraph
Copy link
Contributor

👍

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