Akita: Allow multiple stores under one state folder via schematics

Created on 25 Mar 2020  Β·  20Comments  Β·  Source: datorama/akita

I'm submitting a...

[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ x ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When I add a new feature with ng g af todo/todo there will be generated folder structure like this:

- state
-- feature.model.ts
-- feature.query.ts
-- feature.service.ts
-- feature.store.ts

But now we want to have a structure like this (with a custom folder name _store):

- _store
-- feature
--- feature.model.ts
--- feature.query.ts
--- feature.service.ts
--- feature.store.ts

Expected behavior

There should be a way to customize the root store-foldername from store to _store and create a subfolder for every feature like above.

Minimal reproduction of the problem with instructions

Only execute ng g af toto/todo.

What is the motivation / use case for changing the behavior?

Environment

Angular version: 8.0.0

PR is welcome enhancement good first issue

Most helpful comment

And one can easily combine it with existing --dirName:

ng g af CRM/address --flat false --dirName _store

CRM
└── _store
    └── address
        β”œβ”€β”€ address.model.ts
        β”œβ”€β”€ address.query.ts
        β”œβ”€β”€ address.service.ts
        └── address.store.ts

All 20 comments

@NetanelBasal I can try to take this on.

@Disane87 I took a look at this. So basically instead of ng g af todo/todo you can run ng g af todo/_store/todo --dirName todo to get the desired structure. Is that what you mean?

Or do you want something like ng g af todo/todo --parentDir _store?

@Disane87 As far as I understand, your motivation is to be able to create multiple states for the same feature in a convenient way. For example, you want to run the commands below:

ng g af todo/todos --parentDir _store
ng g af todo/new-todo --parentDir _store

and end up with the following structure:

todo
└── _store
    β”œβ”€β”€ new-todo
    β”‚Β Β  β”œβ”€β”€ new-todo.model.ts
    β”‚Β Β  β”œβ”€β”€ new-todo.query.ts
    β”‚Β Β  β”œβ”€β”€ new-todo.service.ts
    β”‚Β Β  └── new-todo.store.ts
    └── todos
        β”œβ”€β”€ todo.model.ts
        β”œβ”€β”€ todos.query.ts
        β”œβ”€β”€ todos.service.ts
        └── todos.store.ts

Is that right?

@theorlovsky Thank you for your investigation! Need to check that, but apparently I'm pretty busy with stuff going on at work. Gonna report back when I've checked it :)

At first glance, this looks promising.

@theorlovsky it would be great if you can add it to the docs.

@NetanelBasal I guess this issue was closed by mistake, I haven’t finished with this yet.

@theorlovsky I've checked your post from a few days ago. Sorry for the long delay :)

Imageine, I have a module "CRM" where I have a few entities, like addresses or contacts. Now I want to have one single folder under "CRM" with "_store" or whatever and under that for every store a subfolder like this:

└── _store
    β”œβ”€β”€ address
    β”‚   β”œβ”€β”€ address.model.ts
    β”‚   β”œβ”€β”€ address.query.ts
    β”‚   β”œβ”€β”€ address.service.ts
    β”‚   └── address.store.ts
    └── contacts
        β”œβ”€β”€ contacts.model.ts
        β”œβ”€β”€ contacts.query.ts
        β”œβ”€β”€ contacts.service.ts
        └── contacts.store.ts

So your approach seems reasonable and looks like it's working for my juse case.

I'm not sure what's the status of the issue. @Disane87 is @theorlovsky suggestion solved the issue?

@NetanelBasal No IMHO it's not solved because an option like @theorlovsky suggested is not available (--parentDir)

Oh, I thought it's something that exists in Angular schematics :)

Btw _store should be state by default.

└── state
    β”œβ”€β”€ address
    β”‚   β”œβ”€β”€ address.model.ts
    β”‚   β”œβ”€β”€ address.query.ts
    β”‚   β”œβ”€β”€ address.service.ts
    β”‚   └── address.store.ts
    └── contacts
        β”œβ”€β”€ contacts.model.ts
        β”œβ”€β”€ contacts.query.ts
        β”œβ”€β”€ contacts.service.ts
        └── contacts.store.ts

Btw _store should be state by default.

└── state
    β”œβ”€β”€ address
    β”‚   β”œβ”€β”€ address.model.ts
    β”‚   β”œβ”€β”€ address.query.ts
    β”‚   β”œβ”€β”€ address.service.ts
    β”‚   └── address.store.ts
    └── contacts
        β”œβ”€β”€ contacts.model.ts
        β”œβ”€β”€ contacts.query.ts
        β”œβ”€β”€ contacts.service.ts
        └── contacts.store.ts

Indeed state is a better term for this :)

@NetanelBasal so now what I need to do is to basically implement a --flat flag that is true by default for backward compatibility?

No, it should be a new option.

You can add something like:

ng g af CRM/address --grouped
ng g af CRM/contacts --grouped

I thought --flat is a new option since there is no one in akita-cli now. And the usage is:

  • ng g af CRM/address (same as ng g af CRM/address --flat true) – current behavior
  • ng g af CRM/address --flat false – desired behavior:

sh CRM └── state └── address β”œβ”€β”€ address.model.ts β”œβ”€β”€ address.query.ts β”œβ”€β”€ address.service.ts └── address.store.ts

I believe that --flat has more obvious meaning than --grouped.

Agree

And one can easily combine it with existing --dirName:

ng g af CRM/address --flat false --dirName _store

CRM
└── _store
    └── address
        β”œβ”€β”€ address.model.ts
        β”œβ”€β”€ address.query.ts
        β”œβ”€β”€ address.service.ts
        └── address.store.ts

Ok then, I'll open a PR this Saturday

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephencarr picture stephencarr  Β·  4Comments

NetanelBasal picture NetanelBasal  Β·  6Comments

Tobjoern picture Tobjoern  Β·  3Comments

NathanAlcantara picture NathanAlcantara  Β·  4Comments

hoisel picture hoisel  Β·  5Comments