Comments (8)
Right, it most likely doesn't, except when the two pathes are literally the same, but that's a bit limited. Thanks for reminding me.
Though the question whether it uses ==
or the IEquatable interface is a good one. @joethephish do you mind sharing some C# insight on this?
from inkjs.
I found the C# docs super confusing on this issue....!
When searching the current version of the codebase, that comment seems to no longer exist in my C# implementation, I seem to have swapped it back to use SequenceEqual
, with the assumption being that since Path.Component
implements IEquatable
, it'll "do the right thing".
Given that we don't seem to have had any related bugs, I'm assuming it is doing the right thing! (yeah, I'm a professional developer, honest)
So yeah, if the JS implementation uses ==
, it'll need to iterate and do a proper equality comparison.
from inkjs.
so, should the IEquatable's Equals() impl be used instead (if available) when checking for equality for JS/other targets during SequenceEqual(), or would plain "==" always suffice?
from inkjs.
When searching the current version of the codebase, that comment seems to no longer exist in my C# implementation,
I'm pretty sure I wrote that comment as a note to myself and forgot about it later, so it never was in the C# version.
so, should the IEquatable's Equals() impl be used instead (if available) when checking for equality for JS/other targets during SequenceEqual(), or would plain "==" always suffice?
My guess is that it should use the Equals()
(which is already implemented anyway). Two pathes should be considered the same if all their components are equal, not only if they are the same instance? And given that object comparisons in javascript aren't the most reliable anyway, it's probably safer.
from inkjs.
Hmm..yea, there are only 2 classes (Path and Component, which implements IEquatable Equals(other:T):Bool , overriding the default Equals<Runtime.Object> implementation used by the Runtime.Object class it extends from. Looking at the code, as you said, the override is probably there for a purpose, and so I've modified my array sequence equality method with the IEquatable type constraint as well.)
public static function arraySequenceEquals<T:IEquatable<T>>(arr1:Array<T>, arr2:Array<T>):Bool {
if (arr1.length != arr2.length) return false;
for (i in 0...arr1.length) {
if (!arr1[i].Equals(arr2[i])) { // enforced IEquatable constraint
return false;
}
}
return true;
}
For anything outside of that SequenceEquals() case, i can't remember exactly whether there were other cases in the code where Path and Component was checked for "==" and "!=" respectively, though. May probably do a (manual) audit search for such operators being made between/ Path to Path /and /Component to Component/ just in case.
from inkjs.
Alright, I'll do something similar, though I'll probably inline the function. Can you let me know if you find other instances of ==
and !=
in your audit?
from inkjs.
Haven't really looked into yet, but I know for one case... the dev-only debugging method BuildStringOfHierarchy might need to consider it in a sitauation where Path==Path/Component==Component comparisons are made( again...i'm only guessing), and it's more on a yagni-atm basis , since the method isn't actually used in the actual runtime for end-user.
from inkjs.
Fixed in the next release.
from inkjs.
Related Issues (20)
- Error when calling Continue() when canContinue is true HOT 7
- How do I properly set up a PosixFileHandler? HOT 4
- Serverless template Uncaught Error: Failed to convert token to runtime object: "#", but working with ink-full.js HOT 4
- Calling EvaluateFunction() on functions with multiple arguments crashes HOT 5
- Choice tags are gone after state reloading HOT 1
- Bug in LIST_RANGE
- Missing commits in the port HOT 1
- Missing API: cannot bind callback to story.onError HOT 1
- export `JsonSerialisation` HOT 1
- Dynamic Tags are generated in reverse order HOT 2
- scrollDown malfunctions if it needs to scroll up instead HOT 1
- What's the correct syntax for Compiler with JSON file handler? HOT 2
- vite CommonJS error HOT 9
- Can't enumerate variables without accessing private attribute `_globalVariables`
- Compiler export is missing on the newest version HOT 5
- Typescript fails on `import { Story } from 'inkjs';` in 2.2.3 / 2.2.4 HOT 4
- Ink v1.1 support HOT 4
- [v1.1] Runtime port advancement check
- [Help] How to use `PosixFileHandler` in conjunction with Webpack 5 HOT 2
- Compile crash HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inkjs.