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

feat(infra): livedata #5562

Merged
merged 1 commit into from
Jan 30, 2024
Merged

feat(infra): livedata #5562

merged 1 commit into from
Jan 30, 2024

Conversation

EYHN
Copy link
Member

@EYHN EYHN commented Jan 10, 2024

LiveData is a reactive data type.

basic usage

@example

const livedata = new LiveData(0); // create livedata with initial value
 
livedata.next(1); // update value
 
console.log(livedata.value); // get current value
 
livedata.subscribe(v => { // subscribe to value changes
 console.log(v); // 1
});

observable

LiveData is a rxjs observable, you can use rxjs operators.

@example

new LiveData(0).pipe(
  map(v => v + 1),
  filter(v => v > 1),
  ...
)

NOTICE: different from normal observable, LiveData will always emit the latest value when you subscribe to it.

from observable

LiveData can be created from observable or from other livedata.

@example

const A = LiveData.from(
  of(1, 2, 3, 4), // from observable
  0 // initial value
);
 
const B = LiveData.from(
  A.pipe(map(v => 'from a ' + v)), // from other livedata
  '' // initial value
);

NOTICE: LiveData.from will not complete when the observable completes, you can use spreadComplete option to change
this behavior.

Why is it called LiveData

This API is very similar to LiveData in Android, as both are based on Observable, so I named it LiveData.

Copy link

graphite-app bot commented Jan 10, 2024

Your org has enabled the Graphite merge queue for merging into canary

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

You can enable merging using labels in your Graphite merge queue settings.

@EYHN EYHN mentioned this pull request Jan 10, 2024
@github-actions github-actions bot added mod:infra Environment related issues and discussions test Related to test cases labels Jan 10, 2024
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 30 lines in your changes are missing coverage. Please review.

Comparison is base (588b3bc) 64.59% compared to head (c9f8e49) 64.59%.

Files Patch % Lines
packages/common/infra/src/livedata/index.ts 72.97% 18 Missing and 2 partials ⚠️
packages/common/infra/src/livedata/react.ts 9.09% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           canary    #5562   +/-   ##
=======================================
  Coverage   64.59%   64.59%           
=======================================
  Files         296      298    +2     
  Lines       18338    18423   +85     
  Branches     1478     1489   +11     
=======================================
+ Hits        11845    11901   +56     
- Misses       6324     6352   +28     
- Partials      169      170    +1     
Flag Coverage Δ
server-test 70.92% <ø> (+<0.01%) ⬆️
unittest 42.72% <64.70%> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EYHN EYHN force-pushed the eyhn/livedata branch 3 times, most recently from d58d0be to a599eeb Compare January 15, 2024 06:57
@EYHN EYHN force-pushed the eyhn/livedata branch 6 times, most recently from d016a0b to 2f9685b Compare January 23, 2024 16:24
@Brooooooklyn Brooooooklyn changed the title feat(infra): livadata feat(infra): livedata Jan 24, 2024
@pengx17
Copy link
Collaborator

pengx17 commented Jan 24, 2024

Who is this @example?

@EYHN EYHN force-pushed the eyhn/livedata branch 2 times, most recently from 9fdb9ff to c07ae9b Compare January 24, 2024 17:51
@EYHN EYHN force-pushed the eyhn/livedata branch 2 times, most recently from 61df54e to fdb1fd1 Compare January 26, 2024 08:14
Copy link

graphite-app bot commented Jan 30, 2024

Merge activity

LiveData is a reactive data type.

## basic usage

@example
```ts
const livedata = new LiveData(0); // create livedata with initial value

livedata.next(1); // update value

console.log(livedata.value); // get current value

livedata.subscribe(v => { // subscribe to value changes
 console.log(v); // 1
});
```

## observable

LiveData is a rxjs observable, you can use rxjs operators.

@example
```ts
new LiveData(0).pipe(
  map(v => v + 1),
  filter(v => v > 1),
  ...
)
```

NOTICE: different from normal observable, LiveData will always emit the latest value when you subscribe to it.

## from observable

LiveData can be created from observable or from other livedata.

@example
```ts
const A = LiveData.from(
  of(1, 2, 3, 4), // from observable
  0 // initial value
);

const B = LiveData.from(
  A.pipe(map(v => 'from a ' + v)), // from other livedata
  '' // initial value
);
```

NOTICE: LiveData.from will not complete when the observable completes, you can use `spreadComplete` option to change
this behavior.

## Why is it called LiveData

This API is very similar to LiveData in Android, as both are based on Observable, so I named it LiveData.
@graphite-app graphite-app bot merged commit c9f8e49 into canary Jan 30, 2024
36 of 40 checks passed
@graphite-app graphite-app bot deleted the eyhn/livedata branch January 30, 2024 06:42
saranshisatgit pushed a commit to Meta-Root-Zones/AFFiNE that referenced this pull request Jan 30, 2024
LiveData is a reactive data type.

## basic usage

@example
```ts
const livedata = new LiveData(0); // create livedata with initial value

livedata.next(1); // update value

console.log(livedata.value); // get current value

livedata.subscribe(v => { // subscribe to value changes
 console.log(v); // 1
});
```

## observable

LiveData is a rxjs observable, you can use rxjs operators.

@example
```ts
new LiveData(0).pipe(
  map(v => v + 1),
  filter(v => v > 1),
  ...
)
```

NOTICE: different from normal observable, LiveData will always emit the latest value when you subscribe to it.

## from observable

LiveData can be created from observable or from other livedata.

@example
```ts
const A = LiveData.from(
  of(1, 2, 3, 4), // from observable
  0 // initial value
);

const B = LiveData.from(
  A.pipe(map(v => 'from a ' + v)), // from other livedata
  '' // initial value
);
```

NOTICE: LiveData.from will not complete when the observable completes, you can use `spreadComplete` option to change
this behavior.

## Why is it called LiveData

This API is very similar to LiveData in Android, as both are based on Observable, so I named it LiveData.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod:infra Environment related issues and discussions test Related to test cases
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants