-
Notifications
You must be signed in to change notification settings - Fork 34
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
[PLAYER-25] adding api to track event #84
Conversation
be69843
to
31b2790
Compare
c60e513
to
563f577
Compare
563f577
to
af7ea80
Compare
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.
this is promising. Nice architecture as always
src/plugins/FileUpload.js
Outdated
payload: { | ||
category: 'opengapps', | ||
type: 'installed', | ||
name: 'true', |
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.
le name: 'true'
me paraît étrange. ça devrait pas être un truc genre value: 'true'
ou details: 'true'
?
const findChangedKeys = (newState, oldState, path = []) => { | ||
let changedKeys = []; | ||
|
||
const isObject = (obj) => obj && typeof obj === 'object'; | ||
|
||
for (const key in newState) { | ||
const fullPath = [...path, key].join('.'); | ||
|
||
if (!Object.prototype.hasOwnProperty.call(oldState, key)) { | ||
changedKeys.push(fullPath); | ||
} else if (isObject(newState[key]) && isObject(oldState[key])) { | ||
if (Array.isArray(newState[key]) && Array.isArray(oldState[key])) { | ||
if (newState[key].length !== oldState[key].length) { | ||
changedKeys.push(fullPath); | ||
} else { | ||
let arrayHasChanged = false; | ||
for (let i = 0; i < newState[key].length; i++) { | ||
if (newState[key][i] !== oldState[key][i]) { | ||
arrayHasChanged = true; | ||
} | ||
} | ||
if (arrayHasChanged) { | ||
changedKeys.push(fullPath); | ||
} | ||
} | ||
} else { | ||
changedKeys = changedKeys.concat(findChangedKeys(newState[key], oldState[key], [...path, key])); | ||
} | ||
} else if (newState[key] !== oldState[key]) { | ||
changedKeys.push(fullPath); | ||
} | ||
} | ||
|
||
return changedKeys; | ||
}; |
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 would be nice for readibility to refactor this function in order to avoid such deep nesting of conditions & loops. For example by extracting to a function the array check ?
const findChangedKeys = (newState, oldState, path = []) => { | |
let changedKeys = []; | |
const isObject = (obj) => obj && typeof obj === 'object'; | |
for (const key in newState) { | |
const fullPath = [...path, key].join('.'); | |
if (!Object.prototype.hasOwnProperty.call(oldState, key)) { | |
changedKeys.push(fullPath); | |
} else if (isObject(newState[key]) && isObject(oldState[key])) { | |
if (Array.isArray(newState[key]) && Array.isArray(oldState[key])) { | |
if (newState[key].length !== oldState[key].length) { | |
changedKeys.push(fullPath); | |
} else { | |
let arrayHasChanged = false; | |
for (let i = 0; i < newState[key].length; i++) { | |
if (newState[key][i] !== oldState[key][i]) { | |
arrayHasChanged = true; | |
} | |
} | |
if (arrayHasChanged) { | |
changedKeys.push(fullPath); | |
} | |
} | |
} else { | |
changedKeys = changedKeys.concat(findChangedKeys(newState[key], oldState[key], [...path, key])); | |
} | |
} else if (newState[key] !== oldState[key]) { | |
changedKeys.push(fullPath); | |
} | |
} | |
return changedKeys; | |
}; | |
const arraysAreEqual = (firstArray, secondArray) => { | |
if (firstArray.length !== secondArray.length) { | |
return true; | |
} | |
for (let i = 0; i < firstArray.length; i++) { | |
if (firstArray[i] !== secondArray[i]) { | |
return true; | |
} | |
} | |
return false; | |
} | |
const findChangedKeys = (newState, oldState, path = []) => { | |
let changedKeys = []; | |
const isObject = (obj) => obj && typeof obj === 'object'; | |
for (const key in newState) { | |
const fullPath = [...path, key].join('.'); | |
if (!Object.prototype.hasOwnProperty.call(oldState, key)) { | |
changedKeys.push(fullPath); | |
} else if (isObject(newState[key]) && isObject(oldState[key])) { | |
if (Array.isArray(newState[key]) && Array.isArray(oldState[key]) && !arraysAreEqual(newState[key], oldState[key])) { | |
changedKeys.push(fullPath); | |
} else { | |
changedKeys = changedKeys.concat(findChangedKeys(newState[key], oldState[key], [...path, key])); | |
} | |
} else if (newState[key] !== oldState[key]) { | |
changedKeys.push(fullPath); | |
} | |
} | |
return changedKeys; | |
}; |
But there's probably ways to reduce even more the nesting.
29e029c
to
e099e07
Compare
gulpfile.js
Outdated
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.
I don't think this should have been commited
6597c72
to
62e7c79
Compare
Description
Store
Refacto store to subscribe only part of store change. Most likely React useEffect hook, we can now supply an array of dependencies. If no array is supply then the callback will be trigger on each store change
this callback will be trigger only on isKeyboardEventsEnabled change
nested object
Trigger on all change
new feature
Adding functions to ApiManager to track events
Events currently tracked
Type of change
Checklist