Skip to content
This repository has been archived by the owner on Jun 16, 2019. It is now read-only.

ngxs-labs/tree-shaking-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Current behavior

// todo.state.ts

@State<string[]>({
  name: 'todo',
  defaults: []
})
export class TodoState {
 ...
}

@State<TodoStateModel>({
  name: 'todos',
  defaults: {
    todo: [],
    pizza: { model: undefined }
  },
  children: [TodoState]
})
export class TodosState {
  ...
}


// app.module.ts

@NgModule({
  imports: [ NgxsModule.forRoot([TodosState, TodoState]) ]
})
export class AppModule {}

Expected behavior

// todo.state.ts

@State<string[]>({
  name: 'todo',
  defaults: []
})
export class TodoState {
 ...
}

@State<TodoStateModel>({
  name: 'todos',
  defaults: {
    todo: [],
    pizza: { model: undefined }
  },
  children: [TodoState], // default -> providedIn: 'ngxsRoot' for TodoState
  providedIn: 'ngxsRoot'
})
export class TodosState {
  ...
}


// app.module.ts

@NgModule({
  imports: [ NgxsModule.forRoot() ]
})
export class AppModule {}

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

image

/**
 * Options that can be provided to the store.
 */
export interface StoreOptions<T> {
  /**
   * Name of the state. Required.
   */
  name: string;

  /**
   * Default values for the state. If not provided, uses empty object.
   */
  defaults?: T;

  /**
   * Sub states for the given state.
   */
  children?: any[];

  /**
   * Define states in your root module
   * */
  providedIn?: Type<any> | 'ngxsRoot' | null;
}

About

⏱WIP: Improved tree shaking state for NGXS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published