Best JavaScript code snippet using devicefarmer-stf
app.effects.ts
Source:app.effects.ts
1import { Injectable } from '@angular/core';2import {3 AccessToken,4 Activity,5 PagedList,6 Project,7 User,8 UserFeatureFlag9} from '@dev/translatr-model';10import {11 AccessTokenService,12 ActivityService,13 FeatureFlagService,14 ProjectService,15 UserService16} from '@dev/translatr-sdk';17import { Actions, createEffect, Effect, ofType } from '@ngrx/effects';18import { Store } from '@ngrx/store';19import { of } from 'rxjs';20import { catchError, map, switchMap, withLatestFrom } from 'rxjs/operators';21import {22 AccessTokenDeleted,23 AccessTokenDeleteError,24 AccessTokensDeleted,25 AccessTokensDeleteError,26 AccessTokensLoaded,27 AccessTokensLoadError,28 ActivitiesLoaded,29 ActivitiesLoadError,30 AppActionTypes,31 CreateUser,32 DeleteAccessToken,33 DeleteAccessTokens,34 DeleteFeatureFlag,35 DeleteFeatureFlags,36 DeleteProject,37 DeleteProjects,38 DeleteUser,39 DeleteUsers,40 FeatureFlagDeleted,41 FeatureFlagDeleteError,42 FeatureFlagsDeleted,43 FeatureFlagsDeleteError,44 FeatureFlagsLoaded,45 FeatureFlagsLoadError,46 FeatureFlagUpdated,47 FeatureFlagUpdateError,48 LoadAccessTokens,49 LoadActivities,50 LoadFeatureFlags,51 LoadProjects,52 LoadUser,53 LoadUsers,54 LoggedInUserLoaded,55 LoggedInUserLoadError,56 ProjectDeleted,57 ProjectDeleteError,58 ProjectsDeleted,59 ProjectsDeleteError,60 ProjectsLoaded,61 ProjectsLoadError,62 ProjectUpdated,63 ProjectUpdateError,64 UpdateFeatureFlag,65 UpdatePreferredLanguage,66 UpdateProject,67 UpdateUser,68 UserCreated,69 UserCreateError,70 UserDeleted,71 UserDeleteError,72 UserLoaded,73 UserLoadError,74 UsersDeleted,75 UsersDeleteError,76 UsersLoaded,77 UsersLoadError,78 UserUpdated,79 UserUpdateError80} from './app.actions';81import { AppState } from './app.reducer';82import { appQuery } from './app.selectors';83@Injectable()84export class AppEffects {85 // Users86 @Effect() loadMe$ = this.actions$.pipe(87 ofType(AppActionTypes.LoadLoggedInUser),88 switchMap(() =>89 this.userService.me({ fetch: 'featureFlags' }).pipe(90 map(user => new LoggedInUserLoaded(user)),91 catchError(error => of(new LoggedInUserLoadError(error)))92 )93 )94 );95 @Effect() loadUsers$ = this.actions$.pipe(96 ofType(AppActionTypes.LoadUsers),97 switchMap((action: LoadUsers) =>98 this.userService.find(action.payload).pipe(99 map((payload: PagedList<User>) => new UsersLoaded(payload)),100 catchError(error => of(new UsersLoadError(error)))101 )102 )103 );104 @Effect() loadUser$ = this.actions$.pipe(105 ofType(AppActionTypes.LoadUser),106 switchMap((action: LoadUser) =>107 this.userService.get(action.payload.userId).pipe(108 map((payload: User) => new UserLoaded(payload)),109 catchError(error => of(new UserLoadError(error)))110 )111 )112 );113 @Effect() createUser$ = this.actions$.pipe(114 ofType(AppActionTypes.CreateUser),115 switchMap((action: CreateUser) =>116 this.userService.create(action.payload).pipe(117 map((payload: User) => new UserCreated(payload)),118 catchError(error => of(new UserCreateError(error)))119 )120 )121 );122 @Effect() updateUser$ = this.actions$.pipe(123 ofType(AppActionTypes.UpdateUser),124 switchMap((action: UpdateUser) =>125 this.userService.update(action.payload).pipe(126 map((payload: User) => new UserUpdated(payload)),127 catchError(error => of(new UserUpdateError(error)))128 )129 )130 );131 @Effect() deleteUser$ = this.actions$.pipe(132 ofType(AppActionTypes.DeleteUser),133 switchMap((action: DeleteUser) =>134 this.userService.delete(action.payload.id).pipe(135 map((payload: User) => new UserDeleted(payload)),136 catchError(error => of(new UserDeleteError(error)))137 )138 )139 );140 @Effect() deleteUsers$ = this.actions$.pipe(141 ofType(AppActionTypes.DeleteUsers),142 switchMap((action: DeleteUsers) =>143 this.userService.deleteAll(action.payload.map((user: User) => user.id)).pipe(144 map((payload: User[]) => new UsersDeleted(payload)),145 catchError(error => of(new UsersDeleteError(error)))146 )147 )148 );149 // Projects150 @Effect() loadProjects$ = this.actions$.pipe(151 ofType(AppActionTypes.LoadProjects),152 switchMap((action: LoadProjects) =>153 this.projectService.find(action.payload).pipe(154 map((payload: PagedList<Project>) => new ProjectsLoaded(payload)),155 catchError(error => of(new ProjectsLoadError(error)))156 )157 )158 );159 @Effect() updateProject$ = this.actions$.pipe(160 ofType(AppActionTypes.UpdateProject),161 switchMap((action: UpdateProject) =>162 this.projectService.update(action.payload).pipe(163 map((payload: Project) => new ProjectUpdated(payload)),164 catchError(error => of(new ProjectUpdateError(error)))165 )166 )167 );168 @Effect() deleteProject$ = this.actions$.pipe(169 ofType(AppActionTypes.DeleteProject),170 switchMap((action: DeleteProject) =>171 this.projectService.delete(action.payload.id).pipe(172 map((payload: Project) => new ProjectDeleted(payload)),173 catchError(error => of(new ProjectDeleteError(error)))174 )175 )176 );177 @Effect() deleteProjects$ = this.actions$.pipe(178 ofType(AppActionTypes.DeleteProjects),179 switchMap((action: DeleteProjects) =>180 this.projectService.deleteAll(action.payload.map((project: Project) => project.id)).pipe(181 map((payload: Project[]) => new ProjectsDeleted(payload)),182 catchError(error => of(new ProjectsDeleteError(error)))183 )184 )185 );186 // Access Tokens187 @Effect() loadAccessTokens$ = this.actions$.pipe(188 ofType(AppActionTypes.LoadAccessTokens),189 switchMap((action: LoadAccessTokens) =>190 this.accessTokenService.find(action.payload).pipe(191 map((payload: PagedList<AccessToken>) => new AccessTokensLoaded(payload)),192 catchError(error => of(new AccessTokensLoadError(error)))193 )194 )195 );196 @Effect() deleteAccessToken$ = this.actions$.pipe(197 ofType(AppActionTypes.DeleteAccessToken),198 switchMap((action: DeleteAccessToken) =>199 this.accessTokenService.delete(action.payload.id).pipe(200 map((payload: AccessToken) => new AccessTokenDeleted(payload)),201 catchError(error => of(new AccessTokenDeleteError(error)))202 )203 )204 );205 @Effect() deleteAccessTokens$ = this.actions$.pipe(206 ofType(AppActionTypes.DeleteAccessTokens),207 switchMap((action: DeleteAccessTokens) =>208 this.accessTokenService209 .deleteAll(action.payload.map((accessToken: AccessToken) => accessToken.id))210 .pipe(211 map((payload: AccessToken[]) => new AccessTokensDeleted(payload)),212 catchError(error => of(new AccessTokensDeleteError(error)))213 )214 )215 );216 // Activity217 @Effect() loadActivities$ = this.actions$.pipe(218 ofType(AppActionTypes.LoadActivities),219 switchMap((action: LoadActivities) =>220 this.activityService.find(action.payload).pipe(221 map((payload: PagedList<Activity>) => new ActivitiesLoaded(payload)),222 catchError(error => of(new ActivitiesLoadError(error)))223 )224 )225 );226 // Feature Flags227 @Effect() loadFeatureFlags$ = this.actions$.pipe(228 ofType(AppActionTypes.LoadFeatureFlags),229 switchMap((action: LoadFeatureFlags) =>230 this.featureFlagService.find(action.payload).pipe(231 map((payload: PagedList<UserFeatureFlag>) => new FeatureFlagsLoaded(payload)),232 catchError(error => of(new FeatureFlagsLoadError(error)))233 )234 )235 );236 @Effect() updateFeatureFlag$ = this.actions$.pipe(237 ofType(AppActionTypes.UpdateFeatureFlag),238 switchMap((action: UpdateFeatureFlag) =>239 this.featureFlagService.update(action.payload).pipe(240 map((payload: UserFeatureFlag) => new FeatureFlagUpdated(payload)),241 catchError(error => of(new FeatureFlagUpdateError(error)))242 )243 )244 );245 @Effect() deleteFeatureFlag$ = this.actions$.pipe(246 ofType(AppActionTypes.DeleteFeatureFlag),247 switchMap((action: DeleteFeatureFlag) =>248 this.featureFlagService.delete(action.payload.id).pipe(249 map((payload: UserFeatureFlag) => new FeatureFlagDeleted(payload)),250 catchError(error => of(new FeatureFlagDeleteError(error)))251 )252 )253 );254 @Effect() deleteFeatureFlags$ = this.actions$.pipe(255 ofType(AppActionTypes.DeleteFeatureFlags),256 switchMap((action: DeleteFeatureFlags) =>257 this.featureFlagService258 .deleteAll(action.payload.map((featureFlag: UserFeatureFlag) => featureFlag.id))259 .pipe(260 map((payload: UserFeatureFlag[]) => new FeatureFlagsDeleted(payload)),261 catchError(error => of(new FeatureFlagsDeleteError(error)))262 )263 )264 );265 updatePreferredLanguage$ = createEffect(() =>266 this.actions$.pipe(267 ofType(AppActionTypes.UpdatePreferredLanguage),268 withLatestFrom(this.store.select(appQuery.getLoggedInUser)),269 switchMap(([action, me]: [UpdatePreferredLanguage, User]) =>270 this.userService271 .update({ id: me.id, preferredLanguage: action.payload })272 .pipe(map((user: User) => new LoggedInUserLoaded(user)))273 ),274 catchError(error => of(new LoggedInUserLoadError(error)))275 )276 );277 constructor(278 private readonly actions$: Actions,279 private readonly store: Store<AppState>,280 private readonly userService: UserService,281 private readonly projectService: ProjectService,282 private readonly accessTokenService: AccessTokenService,283 private readonly activityService: ActivityService,284 private readonly featureFlagService: FeatureFlagService285 ) {}...
app.facade.ts
Source:app.facade.ts
...141 }142 deleteAccessToken(accessToken: AccessToken) {143 this.store.dispatch(new DeleteAccessToken(accessToken));144 }145 deleteAccessTokens(accessTokens: AccessToken[]) {146 this.store.dispatch(new DeleteAccessTokens(accessTokens));147 }148 unloadAccessTokens() {149 this.unloadAccessTokens$.next();150 }151 // Activity152 loadActivities(criteria: ActivityCriteria) {153 this.store.dispatch(new LoadActivities(criteria));154 }155 // Feature Flags156 loadFeatureFlags(criteria: FeatureFlagCriteria) {157 this.store.dispatch(new LoadFeatureFlags(criteria));158 }159 updateFeatureFlag(featureFlag: UserFeatureFlag): void {...
AccessToken.js
Source:AccessToken.js
...36 createAgent = () => {37 this.props.history.push("/access-token-create");38 }39 removeAgent = (agent) => {40 deleteAccessTokens(agent.id).then((r)=>{41 this.getAgents();42 })43 }44 disableAgent = (agent) => {45 console.log(agent)46 }47 render() {48 if (this.state.loading) {49 return <LoadingIndicator/>50 }51 return (52 <div className="agent-container">53 <div className="container">54 {...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf-client');2var client = devicefarmer.createClient({3});4client.deleteAccessTokens(function (err, res) {5 if (err) {6 console.log(err);7 } else {8 console.log(res);9 }10});11var devicefarmer = require('devicefarmer-stf-client');12var client = devicefarmer.createClient({13});14client.deleteAccessTokens(function (err, res) {15 if (err) {16 console.log(err);17 } else {18 console.log(res);19 }20});21var devicefarmer = require('devicefarmer-stf-client');22var client = devicefarmer.createClient({23});24client.deleteAccessTokens(function (err, res) {25 if (err) {26 console.log(err);27 } else {28 console.log(res);29 }30});31var devicefarmer = require('devicefarmer-stf-client');32var client = devicefarmer.createClient({33});34client.deleteAccessTokens(function (err, res) {35 if (err) {36 console.log(err);37 } else {38 console.log(res);39 }40});41var devicefarmer = require('devicefarmer-stf-client');42var client = devicefarmer.createClient({43});44client.deleteAccessTokens(function (err, res) {45 if (err) {46 console.log(err);47 } else {48 console.log(res);49 }50});51var devicefarmer = require('devicefarmer-stf-client');52var client = devicefarmer.createClient({53});54client.deleteAccessTokens(function (err, res) {55 if (err) {56 console.log(err);57 } else {58 console.log(res);59 }60});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!