-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rambler-digital-solutions/feature/after-ef…
…fects feature afterEffects
- Loading branch information
Showing
17 changed files
with
272 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint-staged | ||
#yarn lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { getTriggerAndStatus } from "./utils"; | ||
import { UpdateOnType } from "./types"; | ||
|
||
/** | ||
* | ||
* key object (__ISALL__: boolean) | ||
* other keys are statuses from array | ||
* value of status keys or __ISALL__ key are biteNames array (to which trigger __afterEffects__ event) | ||
*/ | ||
|
||
/* | ||
** | ||
*/ | ||
|
||
export class AfterEffects { | ||
private finalMap: any = {}; | ||
private removeCheckMap: any = {}; | ||
constructor(private getCurrentTask: () => {type: string, payload: string}) {} | ||
|
||
public handleAfterEffect = (dispather: (action) => void) => { | ||
const currentTask = this.getCurrentTask(); | ||
const dispatchPayload = currentTask; | ||
if(currentTask) { | ||
const {trigger, status} = getTriggerAndStatus(currentTask.type); | ||
if(this.finalMap[trigger]) { | ||
for( let key in this.finalMap[trigger]) { | ||
if(this.finalMap[trigger][key] === '_ALLSTATUSES_') { | ||
setTimeout(()=> { | ||
dispather({ | ||
type: `${key}/__AFTEREFFECTS__`, | ||
payload: dispatchPayload | ||
}) | ||
}) | ||
} | ||
else if(this.finalMap[trigger][key] === status ) { | ||
setTimeout(()=> { | ||
dispather({ | ||
type: `${key}/__AFTEREFFECTS__`, | ||
payload: dispatchPayload | ||
})}) | ||
} | ||
else if(this.finalMap[trigger][key].includes(status)) { | ||
setTimeout(() => { | ||
dispather({ | ||
type: `${key}/__AFTEREFFECTS__`, | ||
payload: dispatchPayload | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
//TODO | ||
} | ||
//check if current task has after effects | ||
//if is => dispatch after effects | ||
|
||
} | ||
|
||
public removeAfterEffect = (biteName:string) => { | ||
if(this.removeCheckMap[biteName]) { | ||
for(let r of this.removeCheckMap[biteName]) { | ||
if(typeof r === 'string') { | ||
delete this.finalMap[r][biteName] | ||
} | ||
else { | ||
const objectkey = Object.keys(r)[0]; | ||
delete this.finalMap[objectkey][biteName] | ||
} | ||
} | ||
} | ||
delete this.removeCheckMap[biteName] | ||
} | ||
|
||
public addAfterEffect = <Tr>(updateOn: UpdateOnType<Tr>, biteName: string) => { | ||
|
||
//add to remove map array | ||
this.removeCheckMap[biteName] = updateOn; | ||
for (let uo of updateOn) { | ||
if(!this.finalMap[uo]) { | ||
this.finalMap[uo] = {} | ||
} | ||
if(typeof uo === 'string') { | ||
this.finalMap[uo][biteName] = '_ALLSTATUSES_' | ||
} | ||
else { | ||
const objectkey = Object.keys(uo)[0]; | ||
const objectValues = uo[objectkey]; | ||
this.finalMap[objectkey][biteName] = objectValues; | ||
} | ||
} | ||
console.log(this.finalMap); | ||
console.log(this.removeCheckMap); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { WatchArgsType,ScriptOptsType, InitArgsType, TriggerPhaseKeys} from "../types"; | ||
|
||
|
||
export abstract class EffectiveScript<RTg, RSt, Bitename extends keyof RTg, PhK extends TriggerPhaseKeys<RTg, Bitename>, Inj=unknown> { | ||
|
||
constructor (opts) { | ||
this.opts = opts | ||
} | ||
|
||
protected opts: ScriptOptsType<RTg, RSt, Bitename, Inj>; | ||
|
||
abstract watch?(args: WatchArgsType<RTg, Bitename>): void | ||
|
||
abstract afterEffects?(args: WatchArgsType<RTg, Bitename>): void | ||
|
||
abstract init(args: InitArgsType<RTg, Bitename, PhK>): void | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getTriggerAndStatus } from "../../utils"; | ||
|
||
export function AfterEffects (instance, action, sliceName) { | ||
const actionPayload = action.payload; | ||
const effectType = actionPayload.type; | ||
const effectPayload = actionPayload.payload; | ||
if(instance.afterEffects) { | ||
const { trigger, status } = getTriggerAndStatus(effectType); | ||
const afterEffectsArgs = { | ||
payload: effectPayload, | ||
trigger, | ||
status, | ||
source: action.source, | ||
sourceSlice: sliceName, | ||
}; | ||
instance.afterEffects(afterEffectsArgs) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getActionType } from '../../utils'; | ||
|
||
export function SetState(store, config, system, uid, sourceSlice) { | ||
|
||
return (status, args) => { | ||
const process = system.findProcessByUid(uid); | ||
if (process.length) { | ||
store.dispatch({ | ||
type: getActionType(config.trigger, status), | ||
payload: args, | ||
source: `${config.trigger}:${uid}`, | ||
sourceSlice, | ||
opts: { | ||
noInit: true, | ||
noUpdate: true, | ||
}, | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
import { getActionType } from '../../utils'; | ||
|
||
export function SetStateNoEffect(store, config, system, uid, sourceSlice) { | ||
|
||
return (status, args) => { | ||
const process = system.findProcessByUid(uid); | ||
if (process.length) { | ||
store.dispatch({ | ||
type: getActionType(config.trigger, status), | ||
payload: args, | ||
source: `${config.trigger}:${uid}`, | ||
sourceSlice, | ||
opts: { | ||
notEffect: true, | ||
noInit: true, | ||
noUpdate: true, | ||
}, | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.