Coder Social home page Coder Social logo

Comments (4)

rniemeyer avatar rniemeyer commented on July 28, 2024

Are you using "data" for anything? Could you pass the id as part of data, then set it on your module in initialize, then read it on dispose?

from knockout-amd-helpers.

vishnurk avatar vishnurk commented on July 28, 2024

Thanks for the response.

I'm using data already to pass global init data into the module.

I have module config details maintained within a config file - including details needed for the amd plugin + additional details(for ex - id, storage key).

The idea is to make the module capable of loading/saving session data from/to local browser storage on initialize/dispose using a key(which comes from configuration).

Also, I find myself throwing in console.log statements for view model level debugging. The 'knockoutJS context debugger' in chrome is unable to drill down to the individual view model details. This might be an unrelated question, thought I'd just mention it to get your feedback.

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on July 28, 2024

Hello- There is not a great way within the module JavaScript code to reach up to the parent and read the moduleInfo object unless you were to require your "app" level module from within your child module, which I personally wouldn't really want to do.

My thought would be to find a way to pass it in with the data. You have some flexibility:

You can include it with your data like:

this.moduleInfo=ko.observable(
{ data: {
      something: "test",
     id: "moduleId"
  },
  name: "modulevm",
  template: "moduleTmpl"
}
);

otherwise, if your "data" is already separate, you can actually pass an array to data and make initialize take multiple arguments like:

this.moduleInfo=ko.observable(
{ data: [{ something: "test" }, "myModuleId" ],
  name: "modulevm",
  template: "moduleTmpl"
}
);

Then, have your initialize look like:

this.initialize  = function(data, moduleId) {
    this.moduleId = moduleId;
};

I think that this last option might be a good choice for your scenario.

from knockout-amd-helpers.

vishnurk avatar vishnurk commented on July 28, 2024

Thanks for the suggestions.

from knockout-amd-helpers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.