-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from SebastianStehle/for-pr
Improvements to the library
- Loading branch information
Showing
289 changed files
with
12,459 additions
and
3,041 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.