Giter Club home page Giter Club logo

data's People

Contributors

andrewdyakin avatar billygoatsoats avatar darumada avatar dependabot[bot] avatar map-lo avatar marcelpotirnac avatar renovate-bot avatar renovate[bot] avatar splincode avatar yoglib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

data's Issues

Problem returning from action with an explicit tysecript class as an explicit payload

Hi, I am trying to follow the example at https://github.com/ngxs-labs/data. However, I am using an explicit typescript class as a payload, and having difficulties in what to return from the action. I would like your help in what should be return in the addAddress and updateAddress actions

import { action, Immutable, NgxsDataRepository, query } from '@ngxs-labs/data'
import { Observable } from 'rxjs'

export interface IFormState {
  dirty?: boolean
  model?: any
}

export class FormState {
  dirty?: boolean = false
  model?: any = undefined
}

export interface IRegistrationStateModel {
  address: IFormState
}

export class RegistrationStateModel {
  address = new FormState()
}

export class RegistrationState extends NgxsDataRepository<IRegistrationStateModel>{
  @query<IRegistrationStateModel, IFormState>((state) => state.address)
  public address$: Observable<IFormState>
  
  @action() addAddress():Immutable<IRegistrationStateModel>{
    return this.ctx.setState((state: Immutable<IRegistrationStateModel>) => address: state.address)
  }
  
  
  @action() updatedAddress():Immutable<IRegistrationStateModel>{
    return 
    
  }
  
}

Dynamic TTL

  • how to set the time dynamically? or is it possible?
  • Is there any event to listen for the time expiration so that we can refresh the data?

ERROR in The pipe 'mutable' could not be found

"@ngxs-labs/data": "2.4.1",

<div>
	<full-calendar
		*ngIf="calendarState$ | async | mutable as calendarState"
		#calendar
		[plugins]="calendarState.plugins"
	></full-calendar>
</div>
  • I have the NgxsDataPluginModule imported in my Store module.

What am I missing?

IE Support?

Guys, do you have any plans to add support for IE11 (at least)?

I would love to use this in my project, but we have to support IE (unfortunately). Will IE 10 / 11 ever be supported?

Also, do you have a roadmap for this lib? About when can we expect it to be prod ready? The labs page says it's "stable".

[WIP]: API

NGXS Data Persistence API

Features implemented

  • Auto providing in NGXS Root/Feature Module
  • Entity manager
  • Query selector (alternative in JPA)
  • Persistence state on IndexDB, LocalStorage, SessionStorage

NGXS States problems

  • Boilerplate problem (we have to describe a lot of actions)
/* DescriptionState, DescriptionSimilarState */

interface DescriptionModel {
  name: string;
  description: string;
}

export class UpdateDescriptionState {
  public static type = 'UpdateDescriptionState '; 
  constuctor(public name: string, public description: string) { }
}

@State<DescriptionModel>({ 
 name: 'myState',
 defaults: { name: null, description: null }
})
class DescriptionState {
  @Action(UpdateDescriptionState)
  public updateState(ctx: StateContext, { name, description }: UpdateMyState) {
    ctx.setState({ name, description });
  }
}

@State<DescriptionModel>({ 
 name: 'myAnotherState',
 defaults: { name: null, description: null }
})
class DescriptionSimilarState {
  @Action(UpdateDescriptionState)
  public updateAlsoState(ctx: StateContext, { name, description }: UpdateMyState) {
    ctx.setState({ name, description });
  }
}

class AppComponent {
  constuctor(private store: Store) {}
  public ngOnInit() {
    // event to DescriptionState, DescriptionSimilarState
    this.store.dispatch(new UpdateDescriptionState('Name', 'Description')); 
  }
}
  • Simple example is very heavy

1) Using Only Dependency Injection

Before

After

import { EntityState, EntityRepository } from '@ngxs-labs/data'; 

@EntityState<MyModel>({ 
 name: 'myState',
 defaults: { name: null, description: null }
})
class MyStateRepository extends EntityRepository<MyModel> {
}

@EntityState<MyModel>({ name: 'myAnotherState' })
class MyAnotherSimilarStateRepository extends MyStateRepository {
}

class AppComponent {
  constructor(
       private myState: MyStateRepository, 
       private similarMyState: MyAnotherSimilarStateRepository
   ) {}

  public ngOnInit() {
    this.myState.setState('Name', 'Description');
    this.similarMyState.setState('Name', 'Description');
  }
}

Working with DeepImmutable... objects

What's the right/most simple way to work with these objects?

Everything I select from my state is wrapped by them, and it really making hard working with my regular types/models.

Initialization of NgxsDataPluginModule in a non-app module

Hi, in your example, to register the NgxsDataPluginModule in the app module the following is used:

...
NgxsDataPluginModule.forRoot({ factory: StateFactory, context: StateContextFactory })
...

How do I accomplish same in a non-app module - there is no NgxsDataPluginModule.forChild() or NgxsDataPluginModule.forFeature() (as is present in NgxsModule.forFeature())

How to use it in resolver?

I'm not able to set state in a resolver. Any tips to how to do it? Current i have the following code:

Service:


@Injectable()
export class HomeService {
  constructor(
    private readonly urlService: HttpUrlService,
    private readonly httpService: HttpClient
  ) { }

  public fetchAll() {
    const url = this.urlService.get('HOME.FETCH');

    return this.httpService.get<{data: HomeModel}>(url).pipe(
      map(response => response.data)
    );
  }
}

State:

@StateRepository()
@State<HomeModel>({
  name: 'home',
  defaults: {
    title: null,
    description: null
  }
})
@Injectable()
export class HomeState extends NgxsDataRepository<HomeModel> {
  @Select(state => state.home)
  public home$: Observable<HomeModel>;

  constructor(
    private readonly homeService: HomeService
  ) {
    super();
  }

  @action()
  public getContent() {
    // this does a httpClient.get()
    return this.homeService.fetchAll().pipe(
      tap(content => this.ctx.setState(() => content ))
    );
  }
}

Then in resolver:


@Injectable()
export class HomeResolver implements Resolve<any> {
  constructor(
    private homeState: HomeState
  ) { }

  public resolve() {
    return this.homeState.getContent();
  }
}

But checking redux tools there is no diff in the state:

image

I'm only able if i explicity .subscribe() the observable, but with that i loose the purpose of a resolver.

On other hand, use it normally as async bind in the view i get the data from the request:

@Component({
  selector: 'ng-lab-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
  home$: Observable<HomeModel>;

  constructor(
    private readonly homeState: HomeState
  ) {}

  ngOnInit() {
    this.home$ = this.homeState.home$;
  }

}

<div class="ui-hero" *ngIf="(home$ | async) as home">
  <h1 class="ui-hero__title">{{home.title}}</h1>
  <p class="ui-hero__info">{{home.description}}</p>
</div>

So i'm a bit confuse because i set state with .setState() and i don't see the data in the state (redux devtools), but using as normal observable data get's renderer in component, is like doesn't set anything related with state but throws data normally thru observables pipes.

Error with typescript v3.5.3 when compiling ngxs-labs/data v2.1.3

Error with typescript v3.5.3 when compiling

error

Dependencies in the project
ng-error

NOTE: I tried to update the typescript to v3.7.4 but after that, I get the angular compiler error as above in the image so I rollbacked to v3.5.3
NodeJS version is 10.16.3

regards.
Shan

Better support for extending NgxsDataEntityCollectionsRepository

We recently switched from ngrx to nxgs with an app that heavily used ngrx/data. Right now we are trying to automate crud operations with our api in a similar way we did with ngrx/data. The route we've chosen is to extend NgxsDataEntityCollectionsRepository to include getAll getOne etc. for now.

Just to share what we are experiencing so far: If we are adding custom fields to the NgxsDataEntityCollectionsRepository reducer, we need to override get snapshot() and getState(). It'd be very nice, if there could be a third generic allowing to specify a type for the NgxsEntityCollections.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.