marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
141 stars 40 forks source link

Pimp docs with good/bad practice section #96

Open maberer opened 8 years ago

maberer commented 8 years ago

Create a "good/bad practice" section in the docs

Please use this issue to add stuff that should be placed in that section.

maberer commented 8 years ago

Good practice In most cases, a handler method is for a single event source Bad practice: The same handler used from different event sources; even worse: from a DOM and custom event source.

maberer commented 8 years ago

Good practice: always put event.preventDefault() for DOM events at the end of the handler. This ensures graceful degradation in case the handler is broken

maberer commented 8 years ago

About having a central store (app architecture...)

Good practice: I think the right thing to do is for only the top-level UI component to connect directly with application state, but there is nothing stopping you from having nested UI components listen directly to a central store. Add 1: Personally, I think it is okay if multiple UI components share the same state as long as the shared state was derived from the same input. Add 2: If you can divide up your UI into multiple and independent parts so that each part is backed by a separate data store then I think that would be beneficial, but that will vary by application

philidem commented 8 years ago

We should cover the directory structure as a best practice.

For components: src/components/**

For pages: src/pages/**

philidem commented 8 years ago

Also, file naming:

patrick-steele-idem commented 8 years ago

One UI component per directory. Only one w-bind attribute should be used in a template. See: https://github.com/marko-js/marko-widgets/issues/95

patrick-steele-idem commented 8 years ago

Declarative event binding > JavaScript event binding

maberer commented 8 years ago

Create a section "Marko/Marko-Widgets" in production. List all prerequisite / important details that are helpful when somebody wants to launch a site in production.

Statement @patrick-steele-idem : Answer to Question: I suspect that on the production machine the node_modules were all flattened and that that broke some of the relative paths that were generated on your development machine.

If you are sure that the project structure is exactly the same between the deployment machine and the production machine then it is better to precompile since there is a cost to compiling templates at runtime (reading from disk, parsing HTML, etc.). However, in most cases you won't notice the compilation cost at runtime since a template is compiled once at startup.