Giter VIP home page Giter VIP logo

Comments (6)

petersirka avatar petersirka commented on August 23, 2024

Hi @eMarek,
no, but you can write route to file:

https://github.com/petersirka/partial.js/blob/master/examples/download-file-counter/controllers/default.js

Be careful, because you lose a features of controller.

from framework.

eMarek avatar eMarek commented on August 23, 2024

Hmmm, I will try. I just testing angular.js a little bit.
So what is the difference between self.responseFile(req, res, self.path.public(filename), filename); and self.file(name + '.html'); as you used it in the issue #22 (comment).

from framework.

petersirka avatar petersirka commented on August 23, 2024

https://github.com/petersirka/partial.js/blob/master/index.js#L5190

Why did you add .json file extension to url?

from framework.

eMarek avatar eMarek commented on August 23, 2024

Hard to explain. :D
I am learning MVVM frameworks and angular.js is one of them. Let's say this way. I make two ajax calls from browser to server. With first one I am getting view. It is pure HTML file with some ng stuff without any data. With second one I am getting date (JSON). This two things (view and data) are combined by the angular.js in the browser. Why am I doing it like this? Because of so called two way data-binding. You can modify JSON and this will be reflected in the DOM tree and vice versa. The idea is sth like this:

exports.install = function(framework) {
    framework.route('/', index);
    framework.route('/products.html', productsHTML, ['+xhr']);
    framework.route('/products.json', productsJSON, ['+xhr']);
};

function index() {
    var self = this;
    self.view('app');
}

function productsHTML() {
    var self = this;
    //returning just view
    self.file('../views/products/index.html');
}

function productsJSON() {
    var self = this;
    //data from DB
    self.json({...});
}

The easiest fix for my problem is to replace dots in routes with dashes.

    framework.route('/products-html', productsHTML, ['+xhr']);
    framework.route('/products-json', productsJSON, ['+xhr']);

Anyway, I will satisfy myself with this ugly notation, if you do not have any better solution. :D
About the controller responding with self.file(...);... It is very usefull, tnx.

from framework.

petersirka avatar petersirka commented on August 23, 2024

Hi, this is my tip:

HTML

  • all templates you can store in public directory
  • is there auto HTTP cache
  • you don't need to write a controller
/public/views/products.html
/public/views/users.html

JSON

  • generate in a controller
  • more options

from framework.

eMarek avatar eMarek commented on August 23, 2024

This solution looks workable but I my case is a little bit to opened. My app will be behind authentication and I do not want to have public views. After all I think I will load views with controller. I have not decided yet.
Anyway, thank you for the help.

from framework.

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.