-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nuzhy/dataManager #763
Merged
prince-deriv
merged 11 commits into
deriv-com:redesign
from
Nuzhy-Deriv:nuzhy/data-manager
Aug 7, 2024
Merged
Nuzhy/dataManager #763
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d112d15
fix: update tradeManager to dataManager
Nuzhy-Deriv d6d9bde
Merge branch 'redesign' into nuzhy/data-manager
Nuzhy-Deriv 88f9ff2
fix: remove unused function
Nuzhy-Deriv f984199
fix: update purchaseManager to dataManager
Nuzhy-Deriv a3f3104
fix: update contractManager to dataManager
Nuzhy-Deriv e77683c
Merge branch 'redesign' into nuzhy/data-manager
Nuzhy-Deriv 8fed1d0
fix: remove unused managers
Nuzhy-Deriv 2bb3dc9
fix: pr comments addressed
Nuzhy-Deriv aa0a503
Merge branch 'redesign' into nuzhy/data-manager
Nuzhy-Deriv 7a4101f
fix: update branch with redesign
Nuzhy-Deriv 150fbdc
fix: refactor data-manager
Nuzhy-Deriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,102 @@ | ||
import { | ||
triggerBarrierChange, | ||
triggerContractChange, | ||
triggerPurchaseChange, | ||
triggerTimeChange, | ||
triggerTradeChange, | ||
} from '../hooks/events'; | ||
|
||
class DataManager { | ||
constructor() { | ||
this.data = { | ||
trade : {}, | ||
purchase: {}, | ||
contract: {}, | ||
}; | ||
} | ||
|
||
set(data, data_type, optional) { | ||
const changeTypeMap = { | ||
trade : 'tradeChange', | ||
purchase: 'purchaseChange', | ||
contract: 'contractChange', | ||
}; | ||
if (typeof data === 'object') { | ||
const oldValues = {}; | ||
const newValues = {}; | ||
Object.entries(data).forEach(([key, value]) => { | ||
if (this.data[data_type][key] !== value) { | ||
oldValues[key] = this.data[data_type][key]; | ||
newValues[key] = value; | ||
} | ||
this.data[data_type][key] = value; | ||
}); | ||
if (Object.keys(newValues).length > 0) { | ||
// Trigger a custom event with old and new values | ||
window.dispatchEvent(new CustomEvent(changeTypeMap[data_type], { | ||
detail: { oldValues, newValues }, | ||
})); | ||
if (optional === 'barrier') { | ||
triggerBarrierChange(); | ||
} else if (optional === 'time') { | ||
triggerTimeChange(); | ||
} else { | ||
switch (data_type) { | ||
case 'trade': | ||
triggerTradeChange(); | ||
break; | ||
|
||
case 'purchase': | ||
triggerPurchaseChange(); | ||
break; | ||
|
||
case 'contract': | ||
triggerContractChange(); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
get(key, data_type) { | ||
return this.data[data_type][key]; | ||
} | ||
|
||
getAll(data_type) { | ||
return { ...this.data[data_type] }; | ||
} | ||
|
||
clear(data_type) { | ||
const oldValues = { ...this.data[data_type] }; | ||
this.data[data_type] = {}; | ||
const changeTypeMap = { | ||
trade : 'tradeChange', | ||
purchase: 'purchaseChange', | ||
contract: 'contractChange', | ||
}; | ||
Nuzhy-Deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
window.dispatchEvent(new CustomEvent(changeTypeMap[data_type], { | ||
detail: { oldValues, newValues: {} }, | ||
})); | ||
if (data_type === 'trade') { | ||
triggerTradeChange(); | ||
} | ||
if (data_type === 'purchase') { | ||
triggerPurchaseChange(); | ||
} | ||
if (data_type === 'contract') { | ||
triggerContractChange(); | ||
} | ||
} | ||
|
||
has(key, data_type) { | ||
return Object.prototype.hasOwnProperty.call(this.data[data_type], key); | ||
} | ||
} | ||
|
||
const dataManager = new DataManager(); | ||
|
||
export default dataManager; |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not clear what the
optional
prop doesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the parameter name to optional_trigger. this is an optional param to set function to triggerBarrierChange, triggerTimeChange only and to separate from tradeChange for not re-rendering everytime barrier, time change.