 
      
    JSON
- 2 ответа
- 0 вопросов
    2
    Вклад в тег
    
      
      
    
  
  
import React from "react"
import styled from "styled-components"
const Button = ({children}) => <a>{children}</a>
const StyledButton = styled(Button)`
  color: green; font-size: 60px; border: 1px solid purple; background: lightblue;
`
const SomeView = () => (
  <div>
    SomeButton: <StyledButton href="/about">about<StyledButton>
  <div>
)class AutoSaveJSON {
    constructor(path) {
        this.data = require(path);
    }
    save() {
        fs.writeFile(path, JSON.stringify(this.data), err => console.dir(err, {colors: true})
    }
    set(key, value) {
        this.data[key] = value;
        this.save()
    }
    get(key) {
        return this.data[key]
    }
}const json = new AutoSaveJSON('./some_data.json')
json.set('key', 'value')
json.get('key') === 'value'