From 0164fc5bd5cbb0862c35650b9eb771f6095ef447 Mon Sep 17 00:00:00 2001 From: Arild Matsson Date: Wed, 15 Jan 2025 18:58:27 +0100 Subject: [PATCH] docs: some cleanup in frontend_devel.md --- doc/frontend_devel.md | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/doc/frontend_devel.md b/doc/frontend_devel.md index 88d1185a..0e7dc38c 100644 --- a/doc/frontend_devel.md +++ b/doc/frontend_devel.md @@ -773,18 +773,7 @@ my_parameter: my value Will make `settings["my_parameter"]` available in the app. -Use `snake_case` when defining new attribute in `config.yml`. Add a default value for the new attribute in `app/scripts/settings.js`, if needed. - -When using the settings object, use the following format: `settings["my_parameter"]`, instead of `settings.my_parameter`. This is to emphasize that `settings` should be viewed as a data structure that is holding values, and to avoid using snake case in code. - -### Map - -Some of the code for the map is located in this repository: - -https://github.com/spraakbanken/korp-geo - -[github-frontend]: https://github.com/spraakbanken/korp-frontend/ -[github-frontend-sb]: https://github.com/spraakbanken/korp-frontend-sb/ +Use `snake_case` when defining new attributes in `config.yml`. Add a default value for the new attribute in `app/scripts/settings.js`, if needed. ### CQP Parser @@ -838,6 +827,8 @@ Use modern features where it looks good. Always use `const` or `let` instead of Identifiers should be in camel case (although our old Korp code may still have some identifiers that uses snake case). +When using the settings object, use `settings["my_parameter"]` instead of `settings.my_parameter`. This is to emphasize that `settings` should be viewed as a data structure that is holding values, and to avoid using snake case in code. + Aim to write code that is easily understood, and supplement with comments as needed. Keep comments up to date while making code changes. Files should be named using snake case: `my_file.js`. @@ -861,28 +852,24 @@ Avoid using directives and controllers. #### Angular.js dependency injection -This is how it looks everywhere in the Angular.js code: +Angular will automatically pass the services demanded by controllers, see https://docs.angularjs.org/guide/di + +Do this (inline array annotation): ```js controller: [ "$scope", - "$rootScope", - "backend", - ($scope, $rootScope, backend) => { - ... - } + function ($scope) { ... } ] ``` -The variables of the controller is created automatically by Angular.js and "injected". When reading documenation online you can find the alternative: +Do not do (implicit annotation): ```js -controller: ($scope, $rootScope, backend) => { - ... -} +controller: function ($scope) { ... } ``` -But this doesn't work in Korp (anymore). Due to minification done by Webpack when building the frontend (`yarn build`). It probably works with `yarn start`, so beware. +This will fail when building the frontend (`yarn build`), due to minification by Webpack. It probably works with `yarn start`, so beware. ### Documentation