Skip to content
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

Objects are passed by reference! #31

Open
Nos78 opened this issue Sep 10, 2020 · 0 comments
Open

Objects are passed by reference! #31

Nos78 opened this issue Sep 10, 2020 · 0 comments

Comments

@Nos78
Copy link
Owner

Nos78 commented Sep 10, 2020

Variable assignment behaviour for JSONs, such as the settings, and other objects is to pass by reference. This means that, for example, creating a new setting from the template and then assigning fields actually changes the template too.

Change this to assign the variables by value, using Object.assign() or another method,

Nos78 added a commit that referenced this issue Sep 10, 2020
…nd other objects is not to pass by value, but by reference. This means that changing the value of the copy modifies the original. This change modifies the assignment of the settings json to protect contents.

Various other changes, such as modifying the help text templated parameters functions, for issue #24, so that they are not so specific to help text description, but so they can be used more generally to replace string templates with a dynamic value, regardless of the context.

+ settings.js
Added two new functions that return a descriptive settings json, describing each field.

+ format.js
Added a new library function to return the type of an object in a better way than the default typeof operator.

+ discord.js
Added a markdown property, which contains the discord mark down

+config.js
Changed the assignment operations for objects.  Added new text template, @ServerName.
New function, replaceJsonTextParameters, loop through and replace template strings in a json object, replacing any template occuring in the name or in the value. Switch statement, using the typeof function, allows different functionality depending on the value of the field. Objects will be treated differently, since the default behaviour is to pass by reference and we don't want this.

+ library/index.js
New jsdoc header for the collateArgs function
Nos78 added a commit that referenced this issue Sep 11, 2020
…user configuration - this change improves caching of the guild configurations, in order to minimise the number of database accesses.

Headers updated for issue #22. Ensuring objects are passed by value where required, for issue #31.

+ System/system.js:
new functions (cacheSettings, cacheParameter) allow a given property of the settings json (we are calling them parameters, although this might be confusing - consider renaming), or the whole object, to be cached into the client.guildSettings for a given guild id. Exceptions will be thrown where the guild id or the client parameters are null.

Re-factor saveParameter, savePrefix, to use the new caching functions where appropriate.

Add missing JSDoc headers for the other exported functions.

saveGuildSettings now throws exceptions.

Renamed getGuildSettings to be more meaningful -> getGuildSettingsFromDb. And added a new function, also named getGuildSettings, which wraps getGuildSettingsFromDb to preserve the existing logic. This new function attempts to acccess the cached settings before accessing the Db. The client parameter has a default value of null to preserve existing logic.

+ bot.js:
New and old version numbers are now logged when upgrading settings objects during the client.on.ready handler.

Removed a re-declaration of a for loop index variable that was already declared.

+ commands/datahelp.js:
Execute is now async, and the function will wait for the database to return the command prefix, in order to fix issue #24 dynamic prefixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant