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

84 bug false information display for number of points count #85

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/event_mixin.plantuml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ skinparam PackageStyle frame
package "event_mixin" {
class EventMixin <<mixin>> {
# setupEventMixin(events_list: Array[String]): void
# createEvent(name: String): void
# deleteEvent(name: String): void
+ subscribeToEvent(event: String, function_handler: Function): void
+ unsubscribeToEvent(event: String, function_handler: Function): void
+ triggerEvent(event: String, ...args: any): void
Expand Down
27 changes: 3 additions & 24 deletions js/utils/event_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,21 @@ export let EventMixin = {
* @memberof EventMixin
* @access protected
*/
_setupEventMixin: function(events_list) {
_setupEventMixin: function (events_list) {
this._event_handlers = {};
for (const event of events_list) {
this._event_handlers[event] = [];
}
},

/**
* Allows a new event for subscription.
* @param {String} name event name
*/
_createEvent: function(name) {
if (this._event_handlers[name] !== undefined) throw new Error("_createEvent: this event already exist.");
this._event_handlers[name] = [];
//TODO test
},

/**
* Removes an event and all its current handlers (they won't be called again).
* The event can't be subscribed to again.
* @param {String} name event name
*/
_deleteEvent: function(name) {
if (this._event_handlers[name] === undefined) throw new Error("_createEvent: this event does not exist.");
delete this._event_handlers[name];
//TODO test
},

/**
* Adds a handler to an event
*
* @param {String} event targetted event
* @param {Function} function_handler callback to associate
* @memberof EventMixin
*/
subscribeToEvent: function(event, function_handler) {
subscribeToEvent: function (event, function_handler) {
// https://stackoverflow.com/questions/12017693/why-use-object-prototype-hasownproperty-callmyobj-prop-instead-of-myobj-hasow
// TD;DR: It is safer this way to avoid it missing or being overriden
if (!Object.prototype.hasOwnProperty.call(this._event_handlers, event)) throw new Error(`"${event}" event doesn't exist.`);
Expand All @@ -80,7 +59,7 @@ export let EventMixin = {
* @param {Function} function_handler callback to associate
* @memberof EventMixin
*/
unsubscribeToEvent: function(event, function_handler) {
unsubscribeToEvent: function (event, function_handler) {
// https://stackoverflow.com/questions/12017693/why-use-object-prototype-hasownproperty-callmyobj-prop-instead-of-myobj-hasow
// TD;DR: It is safer this way to avoid it missing or being overriden
if (!Object.prototype.hasOwnProperty.call(this._event_handlers, event)) throw new Error(`"${event}" event doesn't exist.`);
Expand Down
12 changes: 1 addition & 11 deletions js/utils/state_machine_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import * as equals from "./deep_equals.js";
* add event function for the EventMixin (cleaner), or use a toggled boolean as an
* event dispatcher (quick hack).
*
* The structure is immutable, except for array objects.
*
* @mixin StateMachineMixin
* @export
*/
Expand Down Expand Up @@ -81,7 +79,7 @@ export let StateMachineMixin = {
let val = object[key];
let path = (root === "") ? key : `${root}/${key}`;
keys.push(path);
if (type.IsAnObject(val)) {//object or array? deep explore
if (type.IsAnObject(val) && !type.IsAnArray(val)) {
keys = [...keys, ...this._getStatePaths(val, path)];
}
}
Expand Down Expand Up @@ -142,7 +140,6 @@ export let StateMachineMixin = {

//change the value of the desired key
let is_obj = type.IsAnObject(value) && !type.IsAnArray(value);
let is_array = type.IsAnArray(value);
if (is_obj) {
//if it is an object, change all of its listed states.
let object = value;
Expand All @@ -152,13 +149,6 @@ export let StateMachineMixin = {
if (modifiedLocal) modified = true;
}
}
} else if (is_array) {
//if it is an array, change all of its index values, and create or remove index references as necessary.
let array = value;
for (let i = 0; i < array.length; i++) {
let modifiedLocal = this.setState(`${state_path}/${i}`, array[i], true);
if (modifiedLocal) modified = true;
}
} else {
//assign
if (!equals.deepEquals(container[modified_key], value)) {
Expand Down
2 changes: 1 addition & 1 deletion js/visual_objects/visual_object_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ export class VPVisualizerPointsCount extends VisualObjectProperty {
false,
[{
title: "Points count",
unit: "px",
unit: "",
default_value: this.getCurrentValue(),
min: 0,
step: 1,
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function createWindow () {
win.loadFile("index.html");

// Open the DevTools.
//win.webContents.openDevTools();
win.webContents.openDevTools();

//Hide menu bar
win.setMenuBarVisibility(false);
Expand Down
81 changes: 3 additions & 78 deletions test/renderer/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ describe('utils', () => {
let c = new testClass();
let methods = [
"_setupEventMixin",
"_createEvent",
"_deleteEvent",
"subscribeToEvent",
"unsubscribeToEvent",
"triggerEvent",
Expand Down Expand Up @@ -604,36 +602,6 @@ describe('utils', () => {
c.unsubscribeToEvent("c", func);
expect(c.hasHandlers("c")).to.be.false;
});

it('can create new events', function(done) {
let c = new testClass();
let func = () => {};
this.timeout(1000);

c._createEvent("new_event");
c.subscribeToEvent("new_event", () => {done();});
c.triggerEvent("new_event");
});

it('can delete events', () => {
let c = new testClass();
let func = () => {};

c._deleteEvent("a");
expect(() => {c.triggerEvent("a");}).to.throw();
});

it('cannot delete unknown events', () => {
let c = new testClass();
let func = () => {};
expect(() => {c._deleteEvent("unknown");}).to.throw();
});

it('cannot create existing events', () => {
let c = new testClass();
let func = () => {};
expect(() => {c._createEvent("a");}).to.throw();
});
});
});

Expand Down Expand Up @@ -734,9 +702,6 @@ describe('utils', () => {
expect(class_instance.getState(path)).to.deep.equal(value);
} else if (value instanceof Array) {
expect(class_instance.getState(path)).to.deep.equal(value);
for (let i=0; i < value.length; i++) {
expect(class_instance.getState(path+"/"+i)).to.deep.equal(value[i]);
}
} else {
expect(class_instance.getState(path)).to.equal(value);
}
Expand Down Expand Up @@ -765,9 +730,6 @@ describe('utils', () => {
c.setState("d", {f: "test2"});
expect(c.getState("d")).to.deep.equal({e: true, f: "test2"});
expect(c.getState("d/f")).to.equal("test2");

c.setState("c/0", 3);
expect(c.getState("c/0")).to.equal(3);
});

it('does not allow NaN', () => {
Expand All @@ -783,7 +745,6 @@ describe('utils', () => {
expect(() => {c.getState("d/unknown")}).to.throw();
expect(() => {c.setState("d/unknown", 2)}).to.throw();
expect(() => {c.setState("d", {unknown: "a"})}).to.throw();
expect(() => {c.setState("c/2", 5)}).to.throw();
});

it('supports using validators on states', () => {
Expand All @@ -806,7 +767,7 @@ describe('utils', () => {
let c = new testClass2();

this.timeout(1000);
expect(c._state_paths).to.be.of.length(8);
expect(c._state_paths).to.be.of.length(6);

c.subscribeToState("a", (value) => {
expect(value).to.equal("foo");
Expand All @@ -815,7 +776,7 @@ describe('utils', () => {
c.setState("a", "foo");
});

it('allows to subscribe to a state change happening in children (object)', function(done) {
it('allows to subscribe to a state change happening in children', function(done) {
let c = new testClass2();

this.timeout(1000);
Expand All @@ -827,42 +788,6 @@ describe('utils', () => {
c.setState("d/f", 5);
});

it('allows to subscribe to a state change happening in children (array)', function(done) {
let c = new testClass2();

this.timeout(1000);

c.subscribeToState("c", (value) => {
expect(value[0]).to.deep.equal(15);
done();
})
c.setState("c/0", 15);
});

it('allows to subscribe to a state change happening in parent (object)', function(done) {
let c = new testClass2();

this.timeout(1000);

c.subscribeToState("d/f", (value) => {
expect(value).to.deep.equal(5);
done();
})
c.setState("d", {e: true, f: 5});
});

it('allows to subscribe to a state change happening in parent (array)', function(done) {
let c = new testClass2();

this.timeout(1000);

c.subscribeToState("c", (value) => {
expect(value).to.deep.equal([15,5]);
done();
})
c.setState("c/0", 15);
});

it('lets unsubscribe to state', () => {
let c = new testClass2();
let func = () => {
Expand Down Expand Up @@ -898,7 +823,7 @@ describe('utils', () => {
path: "c",
other_machine: c3,
other_path: "tab",
test_val: [45,87],
test_val: [45,89,87],
},
{
machine: c3,
Expand Down