Skip to content

Commit

Permalink
new version ready but waiting for a new fresh day in case something o…
Browse files Browse the repository at this point in the history
…bvious was missed
  • Loading branch information
Y0ursTruly authored Aug 13, 2024
1 parent 956a031 commit 4f26409
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Share (and sync) Objects Online with the power of websockets. Keys, Values AND R
<br>
**Please note**:
- To view example usage of the modules this library provides, please refer to the _[tests](https://github.com/Y0ursTruly/webject/blob/main/tests.js)_
- Supporting the `Date` type soon. In the meantime it is advised to `Date` instances into their string or number equivalent
- Better example usages would be included later on other than the test file

# Installation
Multiple ways
Expand Down Expand Up @@ -332,6 +332,42 @@ undefined
</ul>

# Structures
## Object
An object being shared can have many attributes and subattributes and even circular references without issue. However the top/root element of data being shared **must be** an `Object` (not an array).<br>
This means, sharing `arr` could be done by sharing `{arr}` and accessing it in connected_data.arr for instance.<br>

#### Unsupported Data Types
- [NaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN)
- [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)

For the instances of data that will be ignored, they will simply not be shared or deleted if they were shared to be a value. Above are the instances of data that will be ignored

#### Supported Data Types
- [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
- [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
- [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
- [null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null)
- [undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)
- [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
- [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
- [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
- [Uint8ClampedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray)
- [Uint16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array)
- [Uint32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array)
- [BigUint64Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array)
- [Int8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array)
- [Int16Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array)
- [Int32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array)
- [Int64Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int64Array)
- [BigInt64Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
- [Float32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)
- [Float64Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array)
- [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)

Now, the list of datatypes are listed above are supported and any other special class that isn't listed here would have its instances of data treated like a regular [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

## Event
Let's look at what is given to `yourReaction` when you call the `addListener` function (which is a method of what is returned after calling the `serve` function)
```
Expand Down Expand Up @@ -378,7 +414,7 @@ the value in ONE index(part) of an objToString array are 1 of the following type
- data is an instance of a datatype to represent a value
- refPath is an index to a referred path located in another index(part) or the path array itself
- num is a number which can be 3 options: 0=not mentioned, 1=mentioned as path, 2=mentioned as reference
- tag is the [Symbol.toStringTag] property of a value and is used for TypedArray, BigInt, Symbol and undefined(which has no [Symbol.toStringTag] but isn't JSON)
- tag is the [Symbol.toStringTag] property of a value and is used for TypedArray, BigInt, Symbol and undefined and newly Date instances (the latter 2 which have no [Symbol.toStringTag] but isn't JSON)
```

## Coding
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webject",
"version": "1.4.8",
"version": "1.4.9",
"description": "Share Objects Online with the power of websockets. Keys, Values AND references. Webject is short for Web Object and it really is a system for sharing objects on the web. Someone can host an object, and make authTokens for others online to share this object",
"main": "webject.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
function isDate(d){
return d? d[toPrimitive]?.bind(test_date)('number')===test_date_num: false;
}
function datesEqual(d1,d2){
return d1[toPrimitive]('number')===d2[toPrimitive]('number')
}
//see if an enumerable property(of key) exists(in obj)
function includes(obj,key){
if(!obj) return false;
Expand All @@ -23,6 +26,7 @@
//see if 2 objects are the "same"(to determine if to overwrite or not)
function same(obj1,obj2){
if(obj1===obj2) return true;
if(isDate(obj1)&&isDate(obj2)&&datesEqual(obj1,obj2)) return true;
if(typeof obj1==="symbol"&&typeof obj2==="symbol")
return obj1.description===obj2.description;
let condition1=typeof(obj1)===typeof(obj2)
Expand All @@ -49,6 +53,7 @@
const nonjson={
__proto__:null,
undefined: function(){return undefined},
Date: function(data){return new Date(data)},
Uint8Array: function(data){return new Uint8Array(data)},
Uint8ClampedArray: function(data){return new Uint8ClampedArray(data)},
Uint16Array: function(data){return new Uint16Array(data)},
Expand All @@ -73,6 +78,8 @@
}
function casingOf(item,forClone){
if(item===undefined || item===null) return forClone? item: null;
if(isDate(item))
return forClone? new Date(item[toPrimitive]('number')): item[toPrimitive]('number');
let tag=item[toStringTag];
if(tag){
if(tag==="Symbol")
Expand Down Expand Up @@ -137,7 +144,7 @@
for(let i=0;i<KEYS.length;i++){
let key=KEYS[i], item=obj[key]
if(includes(clone,key)&&item===clone[key]) continue;
if(typeof item==="function"){
if(typeof item==="function"||(typeof item==="number"&&isNaN(item))){
if(includes(clone,key)){
delete clone[key]
list.push([ [...PATH,key] ]) //delete BECAUSE datatype is function
Expand All @@ -164,11 +171,11 @@
list.push([ path,refPath,mentioned ]) //refer
}
else{
if(item===null || (item===undefined?false:!item[toStringTag]))
if(item===null || (item===undefined?false:!item[toStringTag]&&!isDate(item)))
list.push([ path,casingOf(item) ]); //write
else{
if(item && typeof item!=="bigint") RECURSED.set(item,true);
let datatype=(item||typeof item==="bigint")? item[toStringTag]: "undefined";
let datatype=(item||typeof item==="bigint")? item[toStringTag]||"Date": "undefined";
list.push([ path,casingOf(item),0,datatype ]); //write(for nonjson data types)
}
}
Expand Down

0 comments on commit 4f26409

Please sign in to comment.