Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespaces to actions and reducer #2

Open
farin99 opened this issue Jul 6, 2017 · 3 comments
Open

Add namespaces to actions and reducer #2

farin99 opened this issue Jul 6, 2017 · 3 comments

Comments

@farin99
Copy link

farin99 commented Jul 6, 2017

Cool library!
Did you consider adding a namespace for the *.actions.ts and *.reducer.ts generated files.
e.g.,

teams.actions.ts file will have:

import { Action } from '@ngrx/store';

export namespace TeamUsersActions{
  export const LOAD =                 '[Team Users] Load';
  export const LOAD_SUCCESS =         '[Team Users] Load Success';
  export const LOAD_FAIL =            '[Team Users] Load Fail';
  /**
   * Load Team Users Actions
   */
  export class LoadAction implements Action {
    readonly type = LOAD;
  }

  export class LoadSuccessAction implements Action {
    readonly type = LOAD_SUCCESS;

    constructor(public payload: any) { }
  }

  export class LoadFailAction implements Action {
    readonly type = LOAD_FAIL;

    constructor(public payload: any) { }
  }

  export type Actions =
    | LoadAction
    | LoadSuccessAction
    | LoadFailAction;
}

Then you can use it as:

import {TeamUsersActions} from "./team-users.actions";
TeamUsersActions.LoadAction() and TeamUsersActions.Actions etc.
@NetanelBasal
Copy link
Owner

So you are saving the * as syntax, but I think the compiler generates more code in your example, can you check it, please?

@farin99
Copy link
Author

farin99 commented Jul 9, 2017

It actually seems to create less code 👍 :)

Compiled Code:
With namespace (1619 characters)

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__shared_services_utils__ = __webpack_require__(83);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return TeamUsersActions; });

var TeamUsersActions;
(function (TeamUsersActions) {
    TeamUsersActions.LOAD = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__shared_services_utils__["a" /* type */])('[Team Users] Load');
    TeamUsersActions.LOAD_SUCCESS = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__shared_services_utils__["a" /* type */])('[Team Users] Load Success');
    TeamUsersActions.LOAD_FAIL = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__shared_services_utils__["a" /* type */])('[Team Users] Load Fail');
    /**
     * Load Team Users Actions
     */
    var LoadAction = (function () {
        function LoadAction() {
            this.type = TeamUsersActions.LOAD;
        }
        return LoadAction;
    }());
    TeamUsersActions.LoadAction = LoadAction;
    var LoadSuccessAction = (function () {
        function LoadSuccessAction(payload) {
            this.payload = payload;
            this.type = TeamUsersActions.LOAD_SUCCESS;
        }
        return LoadSuccessAction;
    }());
    TeamUsersActions.LoadSuccessAction = LoadSuccessAction;
    var LoadFailAction = (function () {
        function LoadFailAction(payload) {
            this.payload = payload;
            this.type = TeamUsersActions.LOAD_FAIL;
        }
        return LoadFailAction;
    }());
    TeamUsersActions.LoadFailAction = LoadFailAction;
})(TeamUsersActions || (TeamUsersActions = {}));

without (1716 characters):

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__shared_services_utils__ = __webpack_require__(83);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return LOAD; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return LOAD_SUCCESS; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return LOAD_FAIL; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return LoadAction; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return LoadSuccessAction; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return LoadFailAction; });

var LOAD = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__shared_services_utils__["a" /* type */])('[Team Users] Load');
var LOAD_SUCCESS = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__shared_services_utils__["a" /* type */])('[Team Users] Load Success');
var LOAD_FAIL = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__shared_services_utils__["a" /* type */])('[Team Users] Load Fail');
/**
 * Load Team Users Actions
 */
var LoadAction = (function () {
    function LoadAction() {
        this.type = LOAD;
    }
    return LoadAction;
}());

var LoadSuccessAction = (function () {
    function LoadSuccessAction(payload) {
        this.payload = payload;
        this.type = LOAD_SUCCESS;
    }
    return LoadSuccessAction;
}());

var LoadFailAction = (function () {
    function LoadFailAction(payload) {
        this.payload = payload;
        this.type = LOAD_FAIL;
    }
    return LoadFailAction;
}());

@NetanelBasal
Copy link
Owner

That's interesting! The problem is that many people started writing their applications according to the ngrx official example which is the way I support it. I will examine the matter, and when I have time, I will try to create an option for what you are offering. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants