Skip to content

Commit

Permalink
Merge pull request #55 from SebastianStehle/for-pr
Browse files Browse the repository at this point in the history
Improvements to the library
  • Loading branch information
LSViana authored Oct 31, 2023
2 parents a3053da + 0dbb59c commit a0ec2b5
Show file tree
Hide file tree
Showing 289 changed files with 12,459 additions and 3,041 deletions.
11 changes: 9 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ tab_width = 4
end_of_line = lf
insert_final_newline = true

# C# preferences
csharp_style_namespace_declarations = file_scoped

# StyleCop rules (https://dotnetanalyzers.github.io/StyleCopAnalyzers/)

# Special rules
Expand All @@ -23,7 +26,7 @@ dotnet_diagnostic.SA1008.severity = suggestion # Opening parenthesis should be s
dotnet_diagnostic.SA1009.severity = suggestion # Closing parenthesis should be spaced correctly

# Readability rules
dotnet_diagnostic.SA1101.severity = suggestion # Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none # Prefix local calls with this

# Ordering rules
dotnet_diagnostic.SA1200.severity = suggestion # Using directives should be placed correctly
Expand All @@ -37,4 +40,8 @@ dotnet_diagnostic.SA1413.severity = suggestion # Use trailing comma in multi-lin
dotnet_diagnostic.SA1500.severity = suggestion # Braces for multi-line statements should not share line

# Documentation rules
dotnet_diagnostic.SA1633.severity = suggestion # File should have header
dotnet_diagnostic.SA1600.severity = suggestion # Elements should be documented
dotnet_diagnostic.SA1601.severity = suggestion # Partial elements should be documented
dotnet_diagnostic.SA1602.severity = suggestion # Enumeration items should be documented
dotnet_diagnostic.SA1633.severity = none # File should have header

12 changes: 6 additions & 6 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,40 @@ jobs:

# Linux
- build: linux-x64
os: ubuntu-latest
os: ubuntu-20.04
rust: stable
target: x86_64-unknown-linux-gnu
cross: false

- build: linux-x64-musl
os: ubuntu-latest
os: ubuntu-20.04
rust: stable
target: x86_64-unknown-linux-musl
cross: false

- build: linux-armv7
os: ubuntu-latest
os: ubuntu-20.04
rust: stable
target: armv7-unknown-linux-gnueabihf
linker: gcc-arm-linux-gnueabihf
cross: true

- build: linux-armv7-musl
os: ubuntu-latest
os: ubuntu-20.04
rust: stable
target: armv7-unknown-linux-musleabihf
linker: gcc-arm-linux-gnueabihf
cross: true

- build: linux-arm64
os: ubuntu-latest
os: ubuntu-20.04
rust: stable
target: aarch64-unknown-linux-gnu
linker: gcc-aarch64-linux-gnu
cross: true

- build: linux-arm64-musl
os: ubuntu-latest
os: ubuntu-20.04
rust: stable
target: aarch64-unknown-linux-musl
linker: gcc-aarch64-linux-gnu
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish

on:
push:
branches:
- 'main'
- 'for-pr'
tags:
- 'v*.*.*'

jobs:
pack-nuget:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Download artifacts
uses: dawidd6/action-download-artifact@v2
with:
path: ./output
workflow: build-binaries.yml
workflow_conclusion: success

- name: Nuget pack
run: |
dotnet pack -c Release
- name: Nuget publish
run: |
dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' --skip-duplicate -k ${{ secrets.nuget }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
path: |
**/*.nupkg
10 changes: 5 additions & 5 deletions .github/workflows/build.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Build
name: Test

on:
push:
branches:
- 'main'
- '34-investigate-possible-memory-leaks'
- 'for-pr'

jobs:
test:
runs-on: ${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false

Expand All @@ -28,7 +28,7 @@ jobs:
# macOS
- build: macos
os: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -41,7 +41,7 @@ jobs:
workflow_conclusion: success
name: ${{ matrix.build }}
name_is_regexp: true

- name: Copy binaries
run: |
cp output/${{ matrix.build }}/*.* YDotNet
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Oo]utput/
msbuild.log
msbuild.err
msbuild.wrn
Expand All @@ -39,3 +40,10 @@ msbuild.wrn
# Project-specific files
*.dll
*.dylib

# Node
node_modules

apSettings.Development.json

launchSettings.json
97 changes: 97 additions & 0 deletions Demo/Callback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Text.Json.Serialization;
using YDotNet.Document.Types.Events;
using YDotNet.Extensions;
using YDotNet.Server;

namespace Demo;

public sealed class Callback : IDocumentCallback
{
private readonly ILogger<Callback> log;

public Callback(ILogger<Callback> log)
{
this.log = log;
}

public ValueTask OnDocumentLoadedAsync(DocumentLoadEvent @event)
{
if (@event.Context.DocumentName == "notifications")
{
return default;
}

var map = @event.Document.Map("increment");

map?.ObserveDeep(changes =>
{
foreach (var change in changes)
{
var key = change.MapEvent?.Keys.FirstOrDefault(x => x.Key == "value" && x.Tag != EventKeyChangeTag.Remove);

if (key != null)
{
var valueOld = key.OldValue?.Double;
var valueNew = key.NewValue?.Double;

if (valueOld == valueNew)
{
continue;
}

log.LogInformation("Counter updated from {oldValue} to {newValue}.", valueOld, valueNew);
}
}
});

var chat = @event.Document.Array("stream");

chat?.ObserveDeep(async changes =>
{
var newNotificationsRaw =
changes
.Where(x => x.Tag == EventBranchTag.Array)
.Select(x => x.ArrayEvent)
.SelectMany(x => x.Delta.Where(x => x.Tag == EventChangeTag.Add))
.SelectMany(x => x.Values)
.ToArray();

if (newNotificationsRaw.Length == 0)
{
return;
}

await Task.Delay(100);

var notificationCtx = new DocumentContext("notifications", 0);

await @event.Source.UpdateDocAsync(notificationCtx, (doc) =>
{
List<Notification> notifications;

using (var transaction = @event.Document.ReadTransaction())
{
notifications = newNotificationsRaw.Select(x => x.To<Notification>(transaction)).ToList();
}

var array = doc.Array("stream");

notifications = notifications.Select(x => new Notification { Text = $"You got the follow message: {x.Text}" }).ToList();

using (var transaction = doc.WriteTransaction() ?? throw new InvalidOperationException("Failed to open transaction."))
{
array.InsertRange(transaction, array.Length, notifications.Select(x => x.ToInput()).ToArray());
}
});
});


return default;
}

public sealed class Notification
{
[JsonPropertyName("text")]
public string? Text { get; set; }
}
}
23 changes: 23 additions & 0 deletions Demo/Client/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/semi': 'error',
'@typescript-eslint/indent': [
'warn',
4
]
}
}
24 changes: 24 additions & 0 deletions Demo/Client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions Demo/Client/.vite/deps_temp_bce6eb42/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
27 changes: 27 additions & 0 deletions Demo/Client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
15 changes: 15 additions & 0 deletions Demo/Client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>YJS</title>

<link rel="stylesheet" type="text/css" href="https://prosemirror.net/css/editor.css">
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit a0ec2b5

Please sign in to comment.