Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cfcs/core

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cfcs/core

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
147K
decreased by-0.06%
Maintainers
1
Weekly downloads
 
Created
Source
  • CFCs Reactive

The Hooks component can provide us with a value for the state by changing the state designated as a Hook by certain conditions.

The property/state used in Hooks is called Reactive State.

How to use

Vanilla for Reactive

  1. Define the Component's ReactiveState.
  2. Use ReactiveSubscribe interface for ReactiveState.
  3. Use the @ReactiveSubscribe class decorator to use the subscribe method.
  4. Use the @Observe property decorator to use as reactive state.
import { Observe, Computed, ReactiveSubscribe, ReactiveSubscribe } from "@cfcs/reactive";

export interface ComponentReactiveState {
  state1: boolean;
  state2: number;
  state3: number
}

@ReactiveSubscribe
class Component {
  @Observe() state1!: boolean;
  @Observe() state2!: number;
  @Computed()
  get state3() {
    return this.state1 ? this.state2 : 0;
  }

  // If you want to use it privately and export only public getters, use it as follows.
  @Observe("state1") private _state1!: boolean;
  @Observe("state2") private _state2!: number;
  @Computed("state3")
  get _state3() {
    return this._state1 + this._state2;
  }
}

// if you
interface Component extends ReactiveSubscribe<ComponentReactiveState> {}

export default Component;
import Component from "./Component";

const component = new Component();

const state1 = component.state1;

component.subscribe("state1", nextValue => {
  console.log("subscribe state1 value", nextValue);
});

component.subscribe("state2", nextValue => {
  console.log("subscribe state2 value", nextValue);
});

component.subscribe("state3", nextValue => {
  console.log("subscribe state3 value", nextValue);
});

Framework for Reactive

  1. Define reative hooks for use in framework. There are several preparations.
  • methods to use in the framework. ex) ["resize", "scrollIntoView", "querySelector"]
  • reactive state with default value to use as a hook in the framework. ex) { isReachStart: false, isReachEnd: false }
  • Data interface to deliver framework data to component because the usage method is different for each framework.
  • (dynamic props is in preparation.)
  1. Defines the life cycle that operates in the framework.
  • mounted: ...
  • start: ...
  • destroy: ...
import Component, { ComponentReactiveData } from "./Component";

export interface ComponentData {
  container: HTMLElement;
  props: ComponentOptions;
}

export const COMPONENT_HOOKS: ReactiveAdapter<Component, ComponentReactiveState, ComponentData> = {
  state: COMPONENT_REACTIVE_STATE,
  methods: CONVEYER_METHODS,
  mounted(data) {
    return new Component(data.container, data.props);
  },
  start(instance: Component) {
    instance.init();
  },
  destroy(instance: Component) {
    instance.destroy();
  },
};

Keywords

FAQs

Package last updated on 15 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc