Skip to content

Commit

Permalink
fix: reduce likelihood of name collision by changing _ to __
Browse files Browse the repository at this point in the history
there are times that users would want to define their own private properties. this allows users to follow the common convention of using 1 underscore.
  • Loading branch information
kennyfrc committed Jan 15, 2024
1 parent d2d557e commit 929f5f9
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 206 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

⚠️ Expect API changes until v1.0.0 ⚠️

Current version: 0.3.8.
Current version: 0.3.9.

Bundle Size: 14kb minified & gzipped.

Expand Down
5 changes: 2 additions & 3 deletions build/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/cami.cdn.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions build/cami.module.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/cami.module.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions docs/javascripts/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/javascripts/cami.cdn.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cami",
"version": "0.3.8",
"version": "0.3.9",
"author": "Kenn Costales <[email protected]>",
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions src/cami.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { Observable } from './observables/observable.js';
import { ObservableState, computed, effect } from './observables/observable-state.js';
import { ObservableStream } from './observables/observable-stream.js';
import { ObservableElement } from './observables/observable-element.js';
import { _config } from './config.js';
import { _trace } from './trace.js';
import { __config } from './config.js';
import { __trace } from './trace.js';
import { http } from './http.js';

const { debug, events } = _config;
const { debug, events } = __config;

/**
* @exports store - The store object from observable-store.js. This uses local storage by default.
Expand All @@ -33,7 +33,7 @@ const { debug, events } = _config;
* @exports ObservableState - The ObservableState class from observable-state.js
* @exports ObservableStore - The ObservableStore class from observable-store.js
* @exports http - The http function from http.js
* @exports debug - The debug property from _config
* @exports events - The events property from _config
* @exports debug - The debug property from __config
* @exports events - The events property from __config
*/
export { store, html, svg, ReactiveElement, ObservableStream, ObservableElement, Observable, ObservableState, ObservableStore, http, debug, events, computed, effect };
20 changes: 10 additions & 10 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
* @property {boolean} events - A flag to control event firing
* @description This is the default configuration for Cami.js
*/
const _config = {
const __config = {
events: {
_state: true,
get isEnabled() { return this._state; },
enable: function() { this._state = true; },
disable: function() { this._state = false; }
__state: true,
get isEnabled() { return this.__state; },
enable: function() { this.__state = true; },
disable: function() { this.__state = false; }
},
debug: {
_state: false,
get isEnabled() { return this._state; },
__state: false,
get isEnabled() { return this.__state; },
enable: function() {
console.log('Cami.js debug mode enabled');
this._state = true;
this.__state = true;
},
disable: function() { this._state = false; }
disable: function() { this.__state = false; }
}
};

export { _config };
export { __config };
12 changes: 6 additions & 6 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ObservableStream } from './observables/observable-stream.js';
* @description A class that extends ObservableStream and provides additional methods for handling HTTP requests.
*/
class HTTPStream extends ObservableStream {
_handlers = {};
__handlers = {};

/**
* @method toJson
Expand Down Expand Up @@ -54,10 +54,10 @@ class HTTPStream extends ObservableStream {
* @returns {HTTPStream} The HTTPStream instance.
*/
on(event, handler) {
if (!this._handlers[event]) {
this._handlers[event] = [];
if (!this.__handlers[event]) {
this.__handlers[event] = [];
}
this._handlers[event].push(handler);
this.__handlers[event].push(handler);
return this;
}
}
Expand Down Expand Up @@ -217,8 +217,8 @@ http.sse = (url, config = {}) => {
const source = new EventSource(url, config);

source.onmessage = (event) => {
if (stream._handlers[event.type]) {
stream._handlers[event.type].forEach(handler => handler(event));
if (stream.__handlers[event.type]) {
stream.__handlers[event.type].forEach(handler => handler(event));
}
observer.next(event);
};
Expand Down
Loading

0 comments on commit 929f5f9

Please sign in to comment.