Data model in separate file for reuse?

Hi all,

I need some guidance how to proceed the best way. Switching from c++ to canjs comes with a steep learning curve :slight_smile:

What I’d like to do:
I have my data model structure figured out and want to reuse it in different screens of my application. For each screen I want to have a separate html,css and js file to make sure I don’t create memory leaks etc. Have to figure that out later if really necessary to have all screens in one file.

Now in c++ I would simply put in an include statement for my .h file. Not existing in js and nodejs to my knowledge.

So I dug through the docs and came up with two possible solutions.
a) create my own nodejs-module (how do I do this when I need canMap and canList available)
b) Create a separate can.component which I can reuse (found this in the docs for canjs 2.3 though, so is this still valid?)

Do you know of a third and maybe better solution? If not, which route should I take.

Thanks

Nada

Nada, have you gone through any of the guides? https://canjs.com/doc/guides.html

What type of reuse are you looking for? Generally speaking, different technologies are used for client and server.

Hi justin,

yes I looked into all three tutorials. They were my starting point. Thanks for that :slight_smile:

I try to make the question clearer by changing slightly the scope.

  1. Assume I have a data structure defined
    var myStructure = can.DefineMap.extend({…});
  2. Now I have two different applications
    http://myapp1.myUrl.com
    http://myapp2.myUrl.com
    Different layout, functions etc but at some point both relying on myStructure.
    In addition, each application consist of one html, js and css file.

Of course I could now copy the definition of myStructure into both js files but this would mean in case of a change I have to update both files. It would be much easier if I could just store the datastructure in http://myUrl.com/datastructure.js and have it loaded by the js file of each application.

So reuse would be on the client side.

Cheers,

Nada

Use stealjs or some other module loader to managed shared code. Generally speaking, we publish shared code to npm so it can be versioned.

thx a lot justin. I will then stick with stealjs :slight_smile: